[1562] | 1 | //para.c: |
---|
[1559] | 2 | |
---|
| 3 | /* |
---|
[3811] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010 |
---|
[1559] | 5 | * The code (may) include prototypes and comments (and maybe |
---|
[4038] | 6 | * other code fragements) from OpenBSD's sndio. |
---|
[1559] | 7 | * |
---|
| 8 | * This file is part of libroaresd a part of RoarAudio, |
---|
| 9 | * a cross-platform sound system for both, home and professional use. |
---|
| 10 | * See README for details. |
---|
| 11 | * |
---|
| 12 | * This file is free software; you can redistribute it and/or modify |
---|
| 13 | * it under the terms of the GNU General Public License version 3 |
---|
| 14 | * as published by the Free Software Foundation. |
---|
| 15 | * |
---|
| 16 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 19 | * GNU General Public License for more details. |
---|
| 20 | * |
---|
| 21 | * You should have received a copy of the GNU General Public License |
---|
| 22 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 23 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 24 | * Boston, MA 02110-1301, USA. |
---|
[1559] | 25 | * |
---|
| 26 | * NOTE for everyone want's to change something and send patches: |
---|
| 27 | * read README and HACKING! There a addition information on |
---|
| 28 | * the license of this document you need to read before you send |
---|
| 29 | * any patches. |
---|
| 30 | */ |
---|
| 31 | |
---|
[1571] | 32 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
[1559] | 33 | #include "libroarsndio.h" |
---|
| 34 | |
---|
[1584] | 35 | //#ifndef DEBUG |
---|
| 36 | //#define DEBUG |
---|
| 37 | //#endif |
---|
| 38 | |
---|
[1562] | 39 | void sio_initpar(struct sio_par * par) { |
---|
| 40 | if ( par == NULL ) |
---|
| 41 | return; |
---|
| 42 | |
---|
| 43 | memset(par, 0, sizeof(struct sio_par)); |
---|
| 44 | |
---|
| 45 | par->bits = ROAR_BITS_DEFAULT; |
---|
| 46 | par->sig = 1; |
---|
| 47 | par->le = SIO_LE_NATIVE; |
---|
| 48 | par->msb = 1; |
---|
| 49 | par->rchan = 0; |
---|
| 50 | par->pchan = ROAR_CHANNELS_DEFAULT; |
---|
| 51 | par->rate = ROAR_RATE_DEFAULT; |
---|
| 52 | par->bufsz = ROAR_BITS_DEFAULT * ROAR_CHANNELS_DEFAULT * ROAR_RATE_DEFAULT / 800.0; |
---|
| 53 | par->round = 1; |
---|
| 54 | par->xrun = SIO_IGNORE; |
---|
| 55 | |
---|
| 56 | return; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | int sio_setpar (struct sio_hdl * hdl, struct sio_par * par) { |
---|
[1584] | 60 | if ( hdl == NULL || par == NULL ) { |
---|
| 61 | ROAR_DBG("sio_setpar(*): Invalid handle or parameter pointer"); |
---|
[1566] | 62 | return 0; |
---|
[1584] | 63 | } |
---|
[1566] | 64 | |
---|
[1584] | 65 | if ( par->bits == 0 || par->bits > ROAR_BITS_MAX ) { |
---|
| 66 | ROAR_DBG("sio_setpar(*): Invalid number of bits: %i Bit", par->bits); |
---|
[1566] | 67 | return 0; |
---|
[1584] | 68 | } |
---|
[1566] | 69 | |
---|
| 70 | if ( par->bps == 0 ) |
---|
| 71 | par->bps = SIO_BPS(par->bits); |
---|
| 72 | |
---|
[1584] | 73 | if ( par->bps > ROAR_BITS_MAX/8 ) { |
---|
| 74 | ROAR_DBG("sio_setpar(*): Invalid number of bytes: %i Byte", par->bps); |
---|
[1566] | 75 | return 0; |
---|
[1584] | 76 | } |
---|
[1566] | 77 | |
---|
[1584] | 78 | if ( SIO_BPS(par->bits) > par->bps ) { |
---|
| 79 | ROAR_DBG("sio_setpar(*): Number of bits/8 > number of bytes: %i/8 > %i", par->bits, par->bps); |
---|
[1566] | 80 | return 0; |
---|
[1584] | 81 | } |
---|
[1566] | 82 | |
---|
| 83 | hdl->info.bits = par->bps * 8; |
---|
| 84 | |
---|
| 85 | switch ((par->sig << 4) | par->le) { |
---|
| 86 | case 0x00: |
---|
| 87 | hdl->info.codec = ROAR_CODEC_PCM_U_BE; |
---|
| 88 | break; |
---|
| 89 | case 0x01: |
---|
| 90 | hdl->info.codec = ROAR_CODEC_PCM_U_LE; |
---|
| 91 | break; |
---|
| 92 | case 0x10: |
---|
| 93 | hdl->info.codec = ROAR_CODEC_PCM_S_BE; |
---|
| 94 | break; |
---|
| 95 | case 0x11: |
---|
| 96 | hdl->info.codec = ROAR_CODEC_PCM_S_LE; |
---|
| 97 | break; |
---|
| 98 | default: |
---|
[1584] | 99 | ROAR_DBG("sio_setpar(*): Invalid codec: sig=%i, le=%i", par->sig, par->le); |
---|
[1566] | 100 | return 0; |
---|
| 101 | } |
---|
| 102 | |
---|
[1584] | 103 | if ( par->msb == 0 ) { |
---|
| 104 | ROAR_DBG("sio_setpar(*): LSM alignment not supported"); |
---|
[1566] | 105 | return 0; |
---|
[1584] | 106 | } |
---|
[1566] | 107 | |
---|
[1584] | 108 | if ( par->rchan != 0 ) { /* not supported yet */ |
---|
| 109 | ROAR_DBG("sio_setpar(*): Recording not supported"); |
---|
[1566] | 110 | return 0; |
---|
[1584] | 111 | } |
---|
[1566] | 112 | |
---|
[1584] | 113 | if ( par->pchan == 0 || par->pchan > ROAR_MAX_CHANNELS ) { |
---|
| 114 | ROAR_DBG("sio_setpar(*): Invalid number of playback channels: %i", par->pchan); |
---|
[1566] | 115 | return 0; |
---|
[1584] | 116 | } |
---|
[1566] | 117 | |
---|
| 118 | hdl->info.channels = par->pchan; |
---|
| 119 | |
---|
[1584] | 120 | if ( par->rate == 0 ) { |
---|
| 121 | ROAR_DBG("sio_setpar(*): Invalid sample rate: %iHz", par->rate); |
---|
[1566] | 122 | return 0; |
---|
[1584] | 123 | } |
---|
[1566] | 124 | |
---|
| 125 | hdl->info.rate = par->rate; |
---|
| 126 | |
---|
[1584] | 127 | if ( par->xrun != SIO_IGNORE ) { |
---|
| 128 | ROAR_DBG("sio_setpar(*): Unsupported xrun mode: %i", par->xrun); |
---|
[1566] | 129 | return 0; |
---|
[1584] | 130 | } |
---|
[1566] | 131 | |
---|
[1576] | 132 | memcpy(&(hdl->para), par, sizeof(struct sio_par)); |
---|
| 133 | |
---|
[1566] | 134 | return 1; |
---|
[1562] | 135 | } |
---|
| 136 | |
---|
| 137 | int sio_getpar (struct sio_hdl * hdl, struct sio_par * par) { |
---|
[1576] | 138 | if ( hdl == NULL || par == NULL ) |
---|
| 139 | return 0; |
---|
| 140 | |
---|
| 141 | memcpy(par, &(hdl->para), sizeof(struct sio_par)); |
---|
| 142 | |
---|
| 143 | return 1; |
---|
[1562] | 144 | } |
---|
| 145 | |
---|
| 146 | int sio_getcap (struct sio_hdl * hdl, struct sio_cap * cap) { |
---|
[3240] | 147 | struct roar_stream s; |
---|
[3640] | 148 | unsigned int i; |
---|
| 149 | unsigned int bytes; |
---|
| 150 | unsigned int sign; |
---|
| 151 | unsigned int le; |
---|
| 152 | unsigned int mask = 0; |
---|
[3240] | 153 | |
---|
| 154 | if ( cap == NULL ) |
---|
| 155 | return 0; |
---|
| 156 | |
---|
| 157 | if ( roar_server_oinfo(&(hdl->con), &s) == -1 ) |
---|
| 158 | return 0; |
---|
| 159 | |
---|
| 160 | i = 0; |
---|
| 161 | for (bytes = 1; bytes <= s.info.bits/8; bytes++) { |
---|
| 162 | for (sign = 0; sign < 2; sign++) { |
---|
| 163 | for (le = 0; le < 2; le++) { |
---|
| 164 | cap->enc[i].bits = 8*bytes; |
---|
| 165 | cap->enc[i].bps = bytes; |
---|
| 166 | cap->enc[i].sig = sign; |
---|
| 167 | cap->enc[i].le = le; |
---|
| 168 | cap->enc[i].msb = 1; |
---|
| 169 | mask |= 1 << i; |
---|
| 170 | i++; |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | // TODO: fix this (at least include server channels, |
---|
| 176 | // do nit include confusing setups) |
---|
| 177 | if ( s.info.channels > SIO_NCHAN ) { |
---|
| 178 | s.info.channels = SIO_NCHAN; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | for (i = 0; i < s.info.channels; i++) { |
---|
| 182 | cap->rchan[i] = i+1; |
---|
| 183 | cap->pchan[i] = i+1; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | cap->rate[0] = s.info.rate; |
---|
| 187 | |
---|
| 188 | cap->nconf = 1; |
---|
| 189 | |
---|
| 190 | cap->confs[0].enc = mask; |
---|
| 191 | cap->confs[0].rchan = mask; |
---|
| 192 | cap->confs[0].pchan = mask; |
---|
| 193 | cap->confs[0].rate = 0x0001; |
---|
| 194 | |
---|
| 195 | return 1; |
---|
[1562] | 196 | } |
---|
| 197 | |
---|
| 198 | |
---|
[1559] | 199 | //ll |
---|