source: roaraudio/libroarsndio/para.c @ 1576:76218233e446

Last change on this file since 1576:76218233e446 was 1576:76218233e446, checked in by phi, 15 years ago

added support to get parameters

File size: 3.1 KB
Line 
1//para.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
33#define ROAR_USE_OWN_SNDIO_HDL
34#include "libroarsndio.h"
35
36void   sio_initpar(struct sio_par * par) {
37 if ( par == NULL )
38  return;
39
40 memset(par, 0, sizeof(struct sio_par));
41
42 par->bits  = ROAR_BITS_DEFAULT;
43 par->sig   = 1;
44 par->le    = SIO_LE_NATIVE;
45 par->msb   = 1;
46 par->rchan = 0;
47 par->pchan = ROAR_CHANNELS_DEFAULT;
48 par->rate  = ROAR_RATE_DEFAULT;
49 par->bufsz = ROAR_BITS_DEFAULT * ROAR_CHANNELS_DEFAULT * ROAR_RATE_DEFAULT / 800.0;
50 par->round = 1;
51 par->xrun  = SIO_IGNORE;
52
53 return;
54}
55
56int    sio_setpar (struct sio_hdl * hdl, struct sio_par * par) {
57 if ( hdl == NULL || par == NULL )
58  return 0;
59
60 if ( par->bits == 0 || par->bits > ROAR_BITS_MAX )
61  return 0;
62
63 if ( par->bps == 0 )
64  par->bps = SIO_BPS(par->bits);
65
66 if ( par->bps > ROAR_BITS_MAX/8 )
67  return 0;
68
69 if ( SIO_BPS(par->bits) > par->bps )
70  return 0;
71
72 hdl->info.bits = par->bps * 8;
73
74 switch ((par->sig << 4) | par->le) {
75  case 0x00:
76    hdl->info.codec = ROAR_CODEC_PCM_U_BE;
77   break;
78  case 0x01:
79    hdl->info.codec = ROAR_CODEC_PCM_U_LE;
80   break;
81  case 0x10:
82    hdl->info.codec = ROAR_CODEC_PCM_S_BE;
83   break;
84  case 0x11:
85    hdl->info.codec = ROAR_CODEC_PCM_S_LE;
86   break;
87  default:
88    return 0;
89 }
90
91 if ( par->msb == 0 )
92  return 0;
93
94 if ( par->rchan != 0 ) /* not supported yet */
95  return 0;
96
97 if ( par->pchan == 0 || par->pchan > ROAR_MAX_CHANNELS )
98  return 0;
99
100 hdl->info.channels = par->pchan;
101
102 if ( par->rate == 0 )
103  return 0;
104
105 hdl->info.rate = par->rate;
106
107 if ( par->xrun != SIO_IGNORE )
108  return 0;
109
110 memcpy(&(hdl->para), par, sizeof(struct sio_par));
111
112 return 1;
113}
114
115int    sio_getpar (struct sio_hdl * hdl, struct sio_par * par) {
116 if ( hdl == NULL || par == NULL )
117  return 0;
118
119 memcpy(par, &(hdl->para), sizeof(struct sio_par));
120
121 return 1;
122}
123
124int    sio_getcap (struct sio_hdl * hdl, struct sio_cap * cap) {
125 return 0;
126}
127
128
129//ll
Note: See TracBrowser for help on using the repository browser.