[1555] | 1 | //libroarsndio.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 | |
---|
[1571] | 33 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
[1555] | 34 | #include "libroarsndio.h" |
---|
| 35 | |
---|
[1560] | 36 | struct sio_hdl * sio_open(char * name, unsigned mode, int nbio_flag) { |
---|
| 37 | struct sio_hdl * hdl = NULL; |
---|
[2359] | 38 | int is_midi = 0; |
---|
[1560] | 39 | |
---|
| 40 | if ( (hdl = malloc(sizeof(struct sio_hdl))) == NULL ) |
---|
| 41 | return NULL; |
---|
| 42 | |
---|
| 43 | memset(hdl, 0, sizeof(struct sio_hdl)); |
---|
| 44 | |
---|
[2357] | 45 | switch (mode) { |
---|
| 46 | case SIO_PLAY: |
---|
| 47 | hdl->dir = ROAR_DIR_PLAY; |
---|
| 48 | break; |
---|
| 49 | case MIO_OUT: |
---|
[2359] | 50 | is_midi = 1; |
---|
| 51 | hdl->dir = ROAR_DIR_MIDI_IN; |
---|
| 52 | break; |
---|
[2357] | 53 | case MIO_IN: |
---|
[2359] | 54 | is_midi = 1; |
---|
| 55 | hdl->dir = ROAR_DIR_MIDI_OUT; |
---|
| 56 | break; |
---|
[2360] | 57 | |
---|
| 58 | // unsupported: |
---|
[2357] | 59 | case SIO_REC: |
---|
| 60 | case SIO_PLAY|SIO_REC: |
---|
| 61 | case MIO_OUT|MIO_IN: |
---|
[2360] | 62 | |
---|
| 63 | // illigal: |
---|
[2357] | 64 | default: |
---|
| 65 | free(hdl); |
---|
| 66 | return NULL; |
---|
| 67 | } |
---|
| 68 | |
---|
[2371] | 69 | if ( name == NULL ) { |
---|
| 70 | if ( is_midi ) { |
---|
| 71 | name = getenv("MIDIDEVICE"); |
---|
| 72 | } else { |
---|
| 73 | name = getenv("AUDIODEVICE"); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
[1573] | 77 | if ( roar_simple_connect(&(hdl->con), name, "libroarsndio") == -1 ) { |
---|
| 78 | free(hdl); |
---|
| 79 | return NULL; |
---|
| 80 | } |
---|
| 81 | |
---|
[1560] | 82 | sio_initpar(&(hdl->para)); |
---|
| 83 | |
---|
[2019] | 84 | hdl->stream_opened = 0; |
---|
[1560] | 85 | |
---|
| 86 | if ( name != NULL ) |
---|
| 87 | hdl->device = strdup(name); |
---|
| 88 | |
---|
[2359] | 89 | if ( is_midi ) { |
---|
| 90 | hdl->info.codec = ROAR_CODEC_MIDI; |
---|
| 91 | hdl->info.bits = 8; |
---|
| 92 | hdl->info.channels = 16; |
---|
| 93 | hdl->info.rate = 96; |
---|
| 94 | if ( !sio_start(hdl) ) { |
---|
| 95 | sio_close(hdl); |
---|
| 96 | return NULL; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
[1560] | 100 | return hdl; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | void sio_close (struct sio_hdl * hdl) { |
---|
| 104 | if ( hdl == NULL ) |
---|
| 105 | return; |
---|
| 106 | |
---|
[2019] | 107 | sio_stop(hdl); |
---|
[1560] | 108 | |
---|
[1573] | 109 | roar_disconnect(&(hdl->con)); |
---|
| 110 | |
---|
[1560] | 111 | free(hdl); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | int sio_eof (struct sio_hdl * hdl) { |
---|
| 115 | return 0; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void sio_onmove (struct sio_hdl * hdl, void (*cb)(void * arg, int delta), void * arg) { |
---|
| 119 | if ( hdl == NULL ) |
---|
| 120 | return; |
---|
| 121 | |
---|
| 122 | hdl->on_move = cb; |
---|
| 123 | hdl->on_move_arg = arg; |
---|
| 124 | } |
---|
| 125 | |
---|
[1555] | 126 | //ll |
---|