source: roaraudio/roard/driver_rsound.c @ 3765:1496f402d05d

Last change on this file since 3765:1496f402d05d was 3765:1496f402d05d, checked in by phi, 14 years ago

of cause we should use RSD_U versions in case of _U_ codec

File size: 3.7 KB
Line 
1//driver_rsound.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
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 switch (info->codec) {
78  case ROAR_CODEC_PCM_S_LE:
79    switch (info->bits) {
80     case  8: tmp = RSD_S8;     break;
81     case 16: tmp = RSD_S16_LE; break;
82    }
83   break;
84  case ROAR_CODEC_PCM_S_BE:
85    switch (info->bits) {
86     case  8: tmp = RSD_S8;     break;
87     case 16: tmp = RSD_S16_BE; break;
88    }
89   break;
90  case ROAR_CODEC_PCM_U_LE:
91    switch (info->bits) {
92     case  8: tmp = RSD_U8;     break;
93     case 16: tmp = RSD_U16_LE; break;
94    }
95   break;
96  case ROAR_CODEC_PCM_U_BE:
97    switch (info->bits) {
98     case  8: tmp = RSD_U8;     break;
99     case 16: tmp = RSD_U16_BE; break;
100    }
101   break;
102 }
103
104 if ( tmp == -1 ) {
105  ROAR_DBG("driver_rsound_open(*): Codec/Bits not supported by RSound");
106  rsd_free(self);
107  return -1;
108 }
109
110 tmp2 = tmp;
111
112 if ( rsd_set_param(self, RSD_FORMAT, &tmp) == -1 ) {
113  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_FORMAT, &tmp={0x%x->0x%x}) failed.", tmp2, tmp);
114  rsd_free(self);
115  return -1;
116 }
117
118 if ( tmp != tmp2 ) {
119  rsd_free(self);
120  return -1;
121 }
122
123 if ( rsd_start(self) == -1 ) {
124  ROAR_DBG("driver_rsound_open(*): rsd_start(self) failed.");
125  rsd_free(self);
126  return -1;
127 }
128
129 memset(inst, 0, sizeof(struct roar_vio_calls));
130
131 inst->inst  = self;
132 inst->close = driver_rsound_close;
133 inst->write = driver_rsound_write;
134
135 return 0;
136}
137
138int     driver_rsound_close        (struct roar_vio_calls * vio) {
139 int r = 0;
140
141 if ( rsd_stop(vio->inst) == -1 )
142  r = -1;
143
144 if ( rsd_free(vio->inst) == -1 )
145  r = -1;
146
147 return r;
148}
149
150ssize_t driver_rsound_write        (struct roar_vio_calls * vio, void *buf, size_t count) {
151 size_t ret;
152
153 ret = rsd_write(vio->inst, buf, count);
154
155 if ( ret == 0 )
156  return -1;
157
158 return ret;
159}
160
161#endif
162
163//ll
Note: See TracBrowser for help on using the repository browser.