source: roaraudio/libroarsndio/para.c @ 3640:021567ce5448

Last change on this file since 3640:021567ce5448 was 3640:021567ce5448, checked in by phi, 14 years ago

added -Wextra

File size: 4.9 KB
RevLine 
[1562]1//para.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
[3517]25 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 *  Boston, MA 02110-1301, USA.
[1559]27 *
28 *  NOTE for everyone want's to change something and send patches:
29 *  read README and HACKING! There a addition information on
30 *  the license of this document you need to read before you send
31 *  any patches.
32 */
33
[1571]34#define ROAR_USE_OWN_SNDIO_HDL
[1559]35#include "libroarsndio.h"
36
[1584]37//#ifndef DEBUG
38//#define DEBUG
39//#endif
40
[1562]41void   sio_initpar(struct sio_par * par) {
42 if ( par == NULL )
43  return;
44
45 memset(par, 0, sizeof(struct sio_par));
46
47 par->bits  = ROAR_BITS_DEFAULT;
48 par->sig   = 1;
49 par->le    = SIO_LE_NATIVE;
50 par->msb   = 1;
51 par->rchan = 0;
52 par->pchan = ROAR_CHANNELS_DEFAULT;
53 par->rate  = ROAR_RATE_DEFAULT;
54 par->bufsz = ROAR_BITS_DEFAULT * ROAR_CHANNELS_DEFAULT * ROAR_RATE_DEFAULT / 800.0;
55 par->round = 1;
56 par->xrun  = SIO_IGNORE;
57
58 return;
59}
60
61int    sio_setpar (struct sio_hdl * hdl, struct sio_par * par) {
[1584]62 if ( hdl == NULL || par == NULL ) {
63  ROAR_DBG("sio_setpar(*): Invalid handle or parameter pointer");
[1566]64  return 0;
[1584]65 }
[1566]66
[1584]67 if ( par->bits == 0 || par->bits > ROAR_BITS_MAX ) {
68  ROAR_DBG("sio_setpar(*): Invalid number of bits: %i Bit", par->bits);
[1566]69  return 0;
[1584]70 }
[1566]71
72 if ( par->bps == 0 )
73  par->bps = SIO_BPS(par->bits);
74
[1584]75 if ( par->bps > ROAR_BITS_MAX/8 ) {
76  ROAR_DBG("sio_setpar(*): Invalid number of bytes: %i Byte", par->bps);
[1566]77  return 0;
[1584]78 }
[1566]79
[1584]80 if ( SIO_BPS(par->bits) > par->bps ) {
81  ROAR_DBG("sio_setpar(*): Number of bits/8 > number of bytes: %i/8 > %i", par->bits, par->bps);
[1566]82  return 0;
[1584]83 }
[1566]84
85 hdl->info.bits = par->bps * 8;
86
87 switch ((par->sig << 4) | par->le) {
88  case 0x00:
89    hdl->info.codec = ROAR_CODEC_PCM_U_BE;
90   break;
91  case 0x01:
92    hdl->info.codec = ROAR_CODEC_PCM_U_LE;
93   break;
94  case 0x10:
95    hdl->info.codec = ROAR_CODEC_PCM_S_BE;
96   break;
97  case 0x11:
98    hdl->info.codec = ROAR_CODEC_PCM_S_LE;
99   break;
100  default:
[1584]101    ROAR_DBG("sio_setpar(*): Invalid codec: sig=%i, le=%i", par->sig, par->le);
[1566]102    return 0;
103 }
104
[1584]105 if ( par->msb == 0 ) {
106  ROAR_DBG("sio_setpar(*): LSM alignment not supported");
[1566]107  return 0;
[1584]108 }
[1566]109
[1584]110 if ( par->rchan != 0 ) { /* not supported yet */
111  ROAR_DBG("sio_setpar(*): Recording not supported");
[1566]112  return 0;
[1584]113 }
[1566]114
[1584]115 if ( par->pchan == 0 || par->pchan > ROAR_MAX_CHANNELS ) {
116  ROAR_DBG("sio_setpar(*): Invalid number of playback channels: %i", par->pchan);
[1566]117  return 0;
[1584]118 }
[1566]119
120 hdl->info.channels = par->pchan;
121
[1584]122 if ( par->rate == 0 ) {
123  ROAR_DBG("sio_setpar(*): Invalid sample rate: %iHz", par->rate);
[1566]124  return 0;
[1584]125 }
[1566]126
127 hdl->info.rate = par->rate;
128
[1584]129 if ( par->xrun != SIO_IGNORE ) {
130  ROAR_DBG("sio_setpar(*): Unsupported xrun mode: %i", par->xrun);
[1566]131  return 0;
[1584]132 }
[1566]133
[1576]134 memcpy(&(hdl->para), par, sizeof(struct sio_par));
135
[1566]136 return 1;
[1562]137}
138
139int    sio_getpar (struct sio_hdl * hdl, struct sio_par * par) {
[1576]140 if ( hdl == NULL || par == NULL )
141  return 0;
142
143 memcpy(par, &(hdl->para), sizeof(struct sio_par));
144
145 return 1;
[1562]146}
147
148int    sio_getcap (struct sio_hdl * hdl, struct sio_cap * cap) {
[3240]149 struct roar_stream s;
[3640]150 unsigned int i;
151 unsigned int bytes;
152 unsigned int sign;
153 unsigned int le;
154 unsigned int mask = 0;
[3240]155
156 if ( cap == NULL )
157  return 0;
158
159 if ( roar_server_oinfo(&(hdl->con), &s) == -1 )
160  return 0;
161
162 i = 0;
163 for (bytes = 1; bytes <= s.info.bits/8; bytes++) {
164  for (sign = 0; sign  < 2; sign++) {
165   for (le  = 0; le    < 2; le++) {
166    cap->enc[i].bits =   8*bytes;
167    cap->enc[i].bps  =     bytes;
168    cap->enc[i].sig  =     sign;
169    cap->enc[i].le   =     le;
170    cap->enc[i].msb  =   1;
171    mask |= 1 << i;
172    i++;
173   }
174  }
175 }
176
177 // TODO: fix this (at least include server channels,
178 //                 do nit include confusing setups)
179 if ( s.info.channels > SIO_NCHAN ) {
180  s.info.channels = SIO_NCHAN;
181 }
182
183 for (i = 0; i < s.info.channels; i++) {
184  cap->rchan[i] = i+1;
185  cap->pchan[i] = i+1;
186 }
187
188 cap->rate[0] = s.info.rate;
189
190 cap->nconf = 1;
191
192 cap->confs[0].enc   = mask;
193 cap->confs[0].rchan = mask;
194 cap->confs[0].pchan = mask;
195 cap->confs[0].rate  = 0x0001;
196
197 return 1;
[1562]198}
199
200
[1559]201//ll
Note: See TracBrowser for help on using the repository browser.