source: roaraudio/roard/driver_rsound.c @ 5056:b31e60545552

Last change on this file since 5056:b31e60545552 was 5056:b31e60545552, checked in by phi, 13 years ago

support auto reconf bits=32->16 in case not supported (See: #48)

File size: 4.5 KB
Line 
1//driver_rsound.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#define _DRV_NEED_RSOUND_H
27#include "roard.h"
28
29#ifdef ROAR_HAVE_LIBRSOUND
30
31int     driver_rsound_open         (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
32 rsound_t * self;
33 int tmp, tmp2;
34
35 if ( fh != -1 )
36  return -1;
37
38 if ( rsd_init(&self) == -1 ) {
39  ROAR_DBG("driver_rsound_open(*): rsd_init(&self) failed.");
40  return -1;
41 }
42
43 if ( device != NULL ) {
44  if ( rsd_set_param(self, RSD_HOST, device) == -1 ) {
45   ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_HOST, device) failed.");
46   rsd_free(self);
47   return -1;
48  }
49 }
50
51 tmp = info->channels;
52 if ( rsd_set_param(self, RSD_CHANNELS, &tmp) == -1 ) {
53  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_CHANNELS, &tmp) failed.");
54  rsd_free(self);
55  return -1;
56 }
57
58 if ( tmp != info->channels ) {
59  rsd_free(self);
60  return -1;
61 }
62
63 tmp = info->rate;
64 if ( rsd_set_param(self, RSD_SAMPLERATE, &tmp) == -1 ) {
65  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_SAMPLERATE, &tmp) failed.");
66  rsd_free(self);
67  return -1;
68 }
69
70 if ( tmp != info->rate ) {
71  rsd_free(self);
72  return -1;
73 }
74
75 tmp = -1; // unknown by RSound
76
77 if ( info->bits > 16 && streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF) ) {
78  info->bits = 32;
79 }
80
81 switch (info->codec) {
82  case ROAR_CODEC_PCM_S_LE:
83    switch (info->bits) {
84     case  8: tmp = RSD_S8;     break;
85     case 16: tmp = RSD_S16_LE; break;
86#ifdef RSD_S32_LE
87     case 32: tmp = RSD_S32_LE; break;
88#endif
89    }
90   break;
91  case ROAR_CODEC_PCM_S_BE:
92    switch (info->bits) {
93     case  8: tmp = RSD_S8;     break;
94     case 16: tmp = RSD_S16_BE; break;
95#ifdef RSD_S32_BE
96     case 32: tmp = RSD_S32_BE; break;
97#endif
98    }
99   break;
100  case ROAR_CODEC_PCM_S_PDP:
101    switch (info->bits) {
102     case  8: tmp = RSD_S8;     break;
103    }
104   break;
105  case ROAR_CODEC_PCM_U_LE:
106    switch (info->bits) {
107     case  8: tmp = RSD_U8;     break;
108     case 16: tmp = RSD_U16_LE; break;
109#ifdef RSD_U32_LE
110     case 32: tmp = RSD_U32_LE; break;
111#endif
112    }
113   break;
114  case ROAR_CODEC_PCM_U_BE:
115    switch (info->bits) {
116     case  8: tmp = RSD_U8;     break;
117     case 16: tmp = RSD_U16_BE; break;
118#ifdef RSD_U32_BE
119     case 32: tmp = RSD_U32_BE; break;
120#endif
121    }
122   break;
123  case ROAR_CODEC_PCM_U_PDP:
124    switch (info->bits) {
125     case  8: tmp = RSD_U8;     break;
126    }
127   break;
128 }
129
130#ifdef RSD_S16_NE
131 if ( tmp == -1 && streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF) ) {
132  info->bits  = 16;
133  info->codec = ROAR_CODEC_DEFAULT;
134  tmp         = RSD_S16_NE;
135 }
136#endif
137
138 if ( tmp == -1 ) {
139  ROAR_DBG("driver_rsound_open(*): Codec/Bits not supported by RSound");
140  rsd_free(self);
141  return -1;
142 }
143
144 tmp2 = tmp;
145
146 if ( rsd_set_param(self, RSD_FORMAT, &tmp) == -1 ) {
147  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_FORMAT, &tmp={0x%x->0x%x}) failed.", tmp2, tmp);
148  rsd_free(self);
149  return -1;
150 }
151
152 if ( tmp != tmp2 ) {
153  rsd_free(self);
154  return -1;
155 }
156
157 if ( rsd_start(self) == -1 ) {
158  ROAR_DBG("driver_rsound_open(*): rsd_start(self) failed.");
159  rsd_free(self);
160  return -1;
161 }
162
163 memset(inst, 0, sizeof(struct roar_vio_calls));
164
165 inst->inst     = self;
166 inst->close    = driver_rsound_close;
167 inst->write    = driver_rsound_write;
168 inst->nonblock = driver_dummy_nonblock;
169
170 return 0;
171}
172
173int     driver_rsound_close        (struct roar_vio_calls * vio) {
174 int r = 0;
175
176 if ( rsd_stop(vio->inst) == -1 )
177  r = -1;
178
179 if ( rsd_free(vio->inst) == -1 )
180  r = -1;
181
182 return r;
183}
184
185ssize_t driver_rsound_write        (struct roar_vio_calls * vio, void *buf, size_t count) {
186 size_t ret;
187
188 ret = rsd_write(vio->inst, buf, count);
189
190 if ( ret == 0 )
191  return -1;
192
193 return ret;
194}
195
196#endif
197
198//ll
Note: See TracBrowser for help on using the repository browser.