[1563] | 1 | //stream.c: |
---|
[1559] | 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 | #include "libroarsndio.h" |
---|
| 34 | |
---|
[1567] | 35 | #define _i(x) (hdl->info.x) |
---|
[1563] | 36 | int sio_start (struct sio_hdl * hdl) { |
---|
[1567] | 37 | if ( hdl == NULL ) |
---|
| 38 | return 0; |
---|
| 39 | |
---|
| 40 | if ( hdl->fh != -1 ) |
---|
| 41 | return 0; |
---|
| 42 | |
---|
| 43 | if ( (hdl->fh = roar_simple_play(_i(rate), _i(channels), _i(bits), _i(codec), hdl->device, "libroarsndio")) == -1 ) |
---|
| 44 | return 0; |
---|
| 45 | |
---|
| 46 | return 1; |
---|
[1563] | 47 | } |
---|
[1567] | 48 | #undef _i |
---|
[1563] | 49 | |
---|
| 50 | int sio_stop (struct sio_hdl * hdl) { |
---|
| 51 | |
---|
| 52 | if ( hdl == NULL ) |
---|
| 53 | return 0; |
---|
| 54 | |
---|
| 55 | if ( hdl->fh == -1 ) |
---|
| 56 | return 0; |
---|
| 57 | |
---|
| 58 | close(hdl->fh); |
---|
| 59 | |
---|
| 60 | hdl->fh = -1; |
---|
| 61 | |
---|
| 62 | return 1; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | size_t sio_read (struct sio_hdl * hdl, void * addr, size_t nbytes) { |
---|
| 66 | ssize_t ret; |
---|
| 67 | |
---|
| 68 | if ( hdl == NULL ) |
---|
| 69 | return 0; |
---|
| 70 | |
---|
| 71 | if ( hdl->fh == -1 ) |
---|
| 72 | return 0; |
---|
| 73 | |
---|
| 74 | if ( (ret = read(hdl->fh, addr, nbytes)) < 0 ) |
---|
| 75 | return 0; |
---|
| 76 | |
---|
| 77 | return ret; |
---|
| 78 | } |
---|
| 79 | size_t sio_write (struct sio_hdl * hdl, void * addr, size_t nbytes) { |
---|
| 80 | ssize_t ret; |
---|
| 81 | |
---|
| 82 | if ( hdl == NULL ) |
---|
| 83 | return 0; |
---|
| 84 | |
---|
| 85 | if ( hdl->fh == -1 ) |
---|
| 86 | return 0; |
---|
| 87 | |
---|
| 88 | if ( (ret = write(hdl->fh, addr, nbytes)) < 0 ) |
---|
| 89 | return 0; |
---|
| 90 | |
---|
| 91 | return ret; |
---|
| 92 | } |
---|
| 93 | |
---|
[1559] | 94 | //ll |
---|