source: roaraudio/libroarsndio/para.c @ 4038:5e7b9cca7dd2

Last change on this file since 4038:5e7b9cca7dd2 was 4038:5e7b9cca7dd2, checked in by phi, 14 years ago

some cleanup

File size: 4.8 KB
Line 
1//para.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from OpenBSD's sndio.
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
23 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 *  Boston, MA 02110-1301, USA.
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
32#define ROAR_USE_OWN_SNDIO_HDL
33#include "libroarsndio.h"
34
35//#ifndef DEBUG
36//#define DEBUG
37//#endif
38
39void   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
59int    sio_setpar (struct sio_hdl * hdl, struct sio_par * par) {
60 if ( hdl == NULL || par == NULL ) {
61  ROAR_DBG("sio_setpar(*): Invalid handle or parameter pointer");
62  return 0;
63 }
64
65 if ( par->bits == 0 || par->bits > ROAR_BITS_MAX ) {
66  ROAR_DBG("sio_setpar(*): Invalid number of bits: %i Bit", par->bits);
67  return 0;
68 }
69
70 if ( par->bps == 0 )
71  par->bps = SIO_BPS(par->bits);
72
73 if ( par->bps > ROAR_BITS_MAX/8 ) {
74  ROAR_DBG("sio_setpar(*): Invalid number of bytes: %i Byte", par->bps);
75  return 0;
76 }
77
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);
80  return 0;
81 }
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:
99    ROAR_DBG("sio_setpar(*): Invalid codec: sig=%i, le=%i", par->sig, par->le);
100    return 0;
101 }
102
103 if ( par->msb == 0 ) {
104  ROAR_DBG("sio_setpar(*): LSM alignment not supported");
105  return 0;
106 }
107
108 if ( par->rchan != 0 ) { /* not supported yet */
109  ROAR_DBG("sio_setpar(*): Recording not supported");
110  return 0;
111 }
112
113 if ( par->pchan == 0 || par->pchan > ROAR_MAX_CHANNELS ) {
114  ROAR_DBG("sio_setpar(*): Invalid number of playback channels: %i", par->pchan);
115  return 0;
116 }
117
118 hdl->info.channels = par->pchan;
119
120 if ( par->rate == 0 ) {
121  ROAR_DBG("sio_setpar(*): Invalid sample rate: %iHz", par->rate);
122  return 0;
123 }
124
125 hdl->info.rate = par->rate;
126
127 if ( par->xrun != SIO_IGNORE ) {
128  ROAR_DBG("sio_setpar(*): Unsupported xrun mode: %i", par->xrun);
129  return 0;
130 }
131
132 memcpy(&(hdl->para), par, sizeof(struct sio_par));
133
134 return 1;
135}
136
137int    sio_getpar (struct sio_hdl * hdl, struct sio_par * par) {
138 if ( hdl == NULL || par == NULL )
139  return 0;
140
141 memcpy(par, &(hdl->para), sizeof(struct sio_par));
142
143 return 1;
144}
145
146int    sio_getcap (struct sio_hdl * hdl, struct sio_cap * cap) {
147 struct roar_stream s;
148 unsigned int i;
149 unsigned int bytes;
150 unsigned int sign;
151 unsigned int le;
152 unsigned int mask = 0;
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;
196}
197
198
199//ll
Note: See TracBrowser for help on using the repository browser.