source: roaraudio/roard/driver_rsound.c @ 3726:398771584e72

Last change on this file since 3726:398771584e72 was 3726:398771584e72, checked in by phi, 14 years ago

added a lot debug code

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
29int     driver_rsound_open         (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
30 rsound_t * self;
31 int tmp, tmp2;
32
33 if ( fh != -1 )
34  return -1;
35
36 if ( rsd_init(&self) == -1 ) {
37  ROAR_DBG("driver_rsound_open(*): rsd_init(&self) failed.");
38  return -1;
39 }
40
41 if ( device != NULL ) {
42  if ( rsd_set_param(self, RSD_HOST, device) == -1 ) {
43   ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_HOST, device) failed.");
44   rsd_free(self);
45   return -1;
46  }
47 }
48
49 tmp = info->channels;
50 if ( rsd_set_param(self, RSD_CHANNELS, &tmp) == -1 ) {
51  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_CHANNELS, &tmp) failed.");
52  rsd_free(self);
53  return -1;
54 }
55
56 if ( tmp != info->channels ) {
57  rsd_free(self);
58  return -1;
59 }
60
61 tmp = info->rate;
62 if ( rsd_set_param(self, RSD_SAMPLERATE, &tmp) == -1 ) {
63  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_SAMPLERATE, &tmp) failed.");
64  rsd_free(self);
65  return -1;
66 }
67
68 if ( tmp != info->rate ) {
69  rsd_free(self);
70  return -1;
71 }
72
73 tmp = -1; // unknown by RSound
74
75 switch (info->codec) {
76  case ROAR_CODEC_PCM_S_LE:
77    switch (info->bits) {
78     case  8: tmp = RSD_S8;     break;
79     case 16: tmp = RSD_S16_LE; break;
80    }
81   break;
82  case ROAR_CODEC_PCM_S_BE:
83    switch (info->bits) {
84     case  8: tmp = RSD_S8;     break;
85     case 16: tmp = RSD_S16_BE; break;
86    }
87   break;
88  case ROAR_CODEC_PCM_U_LE:
89    switch (info->bits) {
90     case  8: tmp = RSD_S8;     break;
91     case 16: tmp = RSD_U16_LE; break;
92    }
93   break;
94  case ROAR_CODEC_PCM_U_BE:
95    switch (info->bits) {
96     case  8: tmp = RSD_S8;     break;
97     case 16: tmp = RSD_U16_BE; break;
98    }
99   break;
100 }
101
102 if ( tmp == -1 ) {
103  ROAR_DBG("driver_rsound_open(*): Codec/Bits not supported by RSound");
104  rsd_free(self);
105  return -1;
106 }
107
108 tmp2 = tmp;
109
110 if ( rsd_set_param(self, RSD_FORMAT, &tmp) == -1 ) {
111  ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_FORMAT, &tmp={0x%x->0x%x}) failed.", tmp2, tmp);
112  rsd_free(self);
113  return -1;
114 }
115
116 if ( tmp != tmp2 ) {
117  rsd_free(self);
118  return -1;
119 }
120
121 if ( rsd_start(self) == -1 ) {
122  ROAR_DBG("driver_rsound_open(*): rsd_start(self) failed.");
123  rsd_free(self);
124  return -1;
125 }
126
127 memset(inst, 0, sizeof(struct roar_vio_calls));
128
129 inst->inst  = self;
130 inst->close = driver_rsound_close;
131 inst->write = driver_rsound_write;
132
133 return 0;
134}
135
136int     driver_rsound_close        (struct roar_vio_calls * vio) {
137 int r = 0;
138
139 if ( rsd_stop(vio->inst) == -1 )
140  r = -1;
141
142 if ( rsd_free(vio->inst) == -1 )
143  r = -1;
144
145 return r;
146}
147
148ssize_t driver_rsound_write        (struct roar_vio_calls * vio, void *buf, size_t count) {
149 size_t ret;
150
151 ret = rsd_write(vio->inst, buf, count);
152
153 if ( ret == 0 )
154  return -1;
155
156 return ret;
157}
158
159//ll
Note: See TracBrowser for help on using the repository browser.