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 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, 51 Franklin Street, Fifth Floor, |
---|
26 | * Boston, MA 02110-1301, USA. |
---|
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 | |
---|
34 | #define ROAR_USE_OWN_SNDIO_HDL |
---|
35 | #include "libroarsndio.h" |
---|
36 | |
---|
37 | //#ifndef DEBUG |
---|
38 | //#define DEBUG |
---|
39 | //#endif |
---|
40 | |
---|
41 | void 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 | |
---|
61 | int sio_setpar (struct sio_hdl * hdl, struct sio_par * par) { |
---|
62 | if ( hdl == NULL || par == NULL ) { |
---|
63 | ROAR_DBG("sio_setpar(*): Invalid handle or parameter pointer"); |
---|
64 | return 0; |
---|
65 | } |
---|
66 | |
---|
67 | if ( par->bits == 0 || par->bits > ROAR_BITS_MAX ) { |
---|
68 | ROAR_DBG("sio_setpar(*): Invalid number of bits: %i Bit", par->bits); |
---|
69 | return 0; |
---|
70 | } |
---|
71 | |
---|
72 | if ( par->bps == 0 ) |
---|
73 | par->bps = SIO_BPS(par->bits); |
---|
74 | |
---|
75 | if ( par->bps > ROAR_BITS_MAX/8 ) { |
---|
76 | ROAR_DBG("sio_setpar(*): Invalid number of bytes: %i Byte", par->bps); |
---|
77 | return 0; |
---|
78 | } |
---|
79 | |
---|
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); |
---|
82 | return 0; |
---|
83 | } |
---|
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: |
---|
101 | ROAR_DBG("sio_setpar(*): Invalid codec: sig=%i, le=%i", par->sig, par->le); |
---|
102 | return 0; |
---|
103 | } |
---|
104 | |
---|
105 | if ( par->msb == 0 ) { |
---|
106 | ROAR_DBG("sio_setpar(*): LSM alignment not supported"); |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | if ( par->rchan != 0 ) { /* not supported yet */ |
---|
111 | ROAR_DBG("sio_setpar(*): Recording not supported"); |
---|
112 | return 0; |
---|
113 | } |
---|
114 | |
---|
115 | if ( par->pchan == 0 || par->pchan > ROAR_MAX_CHANNELS ) { |
---|
116 | ROAR_DBG("sio_setpar(*): Invalid number of playback channels: %i", par->pchan); |
---|
117 | return 0; |
---|
118 | } |
---|
119 | |
---|
120 | hdl->info.channels = par->pchan; |
---|
121 | |
---|
122 | if ( par->rate == 0 ) { |
---|
123 | ROAR_DBG("sio_setpar(*): Invalid sample rate: %iHz", par->rate); |
---|
124 | return 0; |
---|
125 | } |
---|
126 | |
---|
127 | hdl->info.rate = par->rate; |
---|
128 | |
---|
129 | if ( par->xrun != SIO_IGNORE ) { |
---|
130 | ROAR_DBG("sio_setpar(*): Unsupported xrun mode: %i", par->xrun); |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | memcpy(&(hdl->para), par, sizeof(struct sio_par)); |
---|
135 | |
---|
136 | return 1; |
---|
137 | } |
---|
138 | |
---|
139 | int sio_getpar (struct sio_hdl * hdl, struct sio_par * par) { |
---|
140 | if ( hdl == NULL || par == NULL ) |
---|
141 | return 0; |
---|
142 | |
---|
143 | memcpy(par, &(hdl->para), sizeof(struct sio_par)); |
---|
144 | |
---|
145 | return 1; |
---|
146 | } |
---|
147 | |
---|
148 | int sio_getcap (struct sio_hdl * hdl, struct sio_cap * cap) { |
---|
149 | struct roar_stream s; |
---|
150 | unsigned int i; |
---|
151 | unsigned int bytes; |
---|
152 | unsigned int sign; |
---|
153 | unsigned int le; |
---|
154 | unsigned int mask = 0; |
---|
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; |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | //ll |
---|