1 | //stream.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
5 | * The code (may) include prototypes and comments (and maybe |
---|
6 | * other code fragements) from EsounD. |
---|
7 | * They are mostly copyrighted by Eric B. Mitchell (aka 'Ricdude) |
---|
8 | * <ericmit@ix.netcom.com>. For more information see AUTHORS.esd. |
---|
9 | * |
---|
10 | * This file is part of libroaresd a part of RoarAudio, |
---|
11 | * a cross-platform sound system for both, home and professional use. |
---|
12 | * See README for details. |
---|
13 | * |
---|
14 | * This file is free software; you can redistribute it and/or modify |
---|
15 | * it under the terms of the GNU General Public License version 3 |
---|
16 | * as published by the Free Software Foundation. |
---|
17 | * |
---|
18 | * RoarAudio is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with this software; see the file COPYING. If not, write to |
---|
25 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
26 | * |
---|
27 | * NOTE for everyone want's to change something and send patches: |
---|
28 | * read README and HACKING! There a addition information on |
---|
29 | * the license of this document you need to read before you send |
---|
30 | * any patches. |
---|
31 | */ |
---|
32 | |
---|
33 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
34 | #include "libroarsndio.h" |
---|
35 | |
---|
36 | #define _i(x) (hdl->info.x) |
---|
37 | int sio_start (struct sio_hdl * hdl) { |
---|
38 | if ( hdl == NULL ) |
---|
39 | return 0; |
---|
40 | |
---|
41 | if ( hdl->fh != -1 ) |
---|
42 | return 0; |
---|
43 | |
---|
44 | if ( (hdl->fh = roar_simple_new_stream_obj(&(hdl->con), &(hdl->stream), _i(rate), _i(channels), _i(bits), _i(codec), ROAR_DIR_PLAY)) == -1 ) |
---|
45 | return 0; |
---|
46 | |
---|
47 | return 1; |
---|
48 | } |
---|
49 | #undef _i |
---|
50 | |
---|
51 | int sio_stop (struct sio_hdl * hdl) { |
---|
52 | |
---|
53 | if ( hdl == NULL ) |
---|
54 | return 0; |
---|
55 | |
---|
56 | if ( hdl->fh == -1 ) |
---|
57 | return 0; |
---|
58 | |
---|
59 | close(hdl->fh); |
---|
60 | |
---|
61 | hdl->fh = -1; |
---|
62 | |
---|
63 | return 1; |
---|
64 | } |
---|
65 | |
---|
66 | size_t sio_read (struct sio_hdl * hdl, void * addr, size_t nbytes) { |
---|
67 | ssize_t ret; |
---|
68 | |
---|
69 | if ( hdl == NULL ) |
---|
70 | return 0; |
---|
71 | |
---|
72 | if ( hdl->fh == -1 ) |
---|
73 | return 0; |
---|
74 | |
---|
75 | if ( (ret = read(hdl->fh, addr, nbytes)) < 0 ) |
---|
76 | return 0; |
---|
77 | |
---|
78 | return ret; |
---|
79 | } |
---|
80 | size_t sio_write (struct sio_hdl * hdl, void * addr, size_t nbytes) { |
---|
81 | ssize_t ret; |
---|
82 | |
---|
83 | if ( hdl == NULL ) |
---|
84 | return 0; |
---|
85 | |
---|
86 | if ( hdl->fh == -1 ) |
---|
87 | return 0; |
---|
88 | |
---|
89 | if ( (ret = write(hdl->fh, addr, nbytes)) < 0 ) |
---|
90 | return 0; |
---|
91 | |
---|
92 | if ( hdl->on_move != NULL ) { |
---|
93 | hdl->on_move(hdl->on_move_arg, 8*ret/(hdl->info.channels * hdl->info.bits)); |
---|
94 | } |
---|
95 | |
---|
96 | return ret; |
---|
97 | } |
---|
98 | |
---|
99 | //ll |
---|