source: roaraudio/roard/driver_sndio.c @ 1547:751826b3e553

Last change on this file since 1547:751826b3e553 was 1547:751826b3e553, checked in by phi, 15 years ago

started writing some code

File size: 3.6 KB
Line 
1//driver_sndio.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26#ifdef ROAR_HAVE_LIBSNDIO
27
28int driver_sndio_init_vio(struct roar_vio_calls * vio, struct driver_sndio * inst) {
29 if ( vio == NULL )
30  return -1;
31
32 memset(vio, 0, sizeof(struct roar_vio_calls));
33
34 vio->close    = driver_sndio_close_vio;
35 vio->write    = driver_sndio_write;
36 vio->sync     = driver_sndio_sync;
37 vio->ctl      = driver_sndio_ctl;
38
39 vio->inst     = (void*) inst;
40
41 return 0;
42}
43
44#define er() if ( self->handle ) sio_close(self->handle); if ( self->device ) free(self->device); free(self); return -1
45int driver_sndio_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) {
46 struct driver_sndio * self = NULL;
47
48 if ( (self = malloc(sizeof(struct driver_sndio))) == NULL ) {
49  ROAR_ERR("driver_sndio_open(*): Can not malloc() instance data: %s", strerror(errno));
50  return -1;
51 }
52
53 memset(self, 0, sizeof(struct driver_sndio));
54 memcpy(&(self->info), info, sizeof(struct roar_audio_info));
55
56 self->ssid = -1;
57
58 if ( device != NULL )
59  self->device = strdup(device);
60
61 if ( driver_sndio_init_vio(inst, self) == -1 ) {
62  ROAR_ERR("driver_sndio_open(*): Can not init vio interface");
63  er();
64 }
65
66 if ( driver_sndio_open_device(self) == -1 ) {
67  ROAR_ERR("driver_sndio_open(*): Can not open audio device");
68  er();
69 }
70
71 ROAR_DBG("driver_sndio_open(*): OSS devices opened :)");
72
73 return 0;
74}
75#undef er
76
77int     driver_sndio_close_vio    (struct roar_vio_calls * vio) {
78 struct driver_sndio * self = vio->inst;
79
80 if ( self->handle != NULL )
81  sio_close(self->handle);
82
83 if ( self->device != NULL )
84  free(self->device);
85
86 free(self);
87
88 return 0;
89}
90
91int     driver_sndio_open_device  (struct driver_sndio * self) {
92
93 if ( (self->handle = sio_open(self->device, SIO_PLAY, 0)) == NULL ) {
94  ROAR_ERR("driver_sndio_open_device(*): Can not open sndio audio device");
95  return -1;
96 }
97
98 return 0;
99}
100
101int     driver_sndio_config_device(struct driver_sndio * self) {
102 struct sio_par par;
103
104 sio_initpar(&par);
105
106 par.bits  = self->info.bits;
107 par.rate  = self->info.rate;
108 par.pchan = self->info.channels;
109
110 switch (self->info.codec) {
111  case ROAR_CODEC_PCM_S_LE:
112    par.le  = 1;
113    par.sig = 1;
114   break;
115  case ROAR_CODEC_PCM_S_BE:
116    par.le  = 0;
117    par.sig = 1;
118   break;
119  case ROAR_CODEC_PCM_U_LE:
120    par.le  = 1;
121    par.sig = 0;
122   break;
123  case ROAR_CODEC_PCM_U_BE:
124    par.le  = 0;
125    par.sig = 0;
126   break;
127  default:
128    return -1;
129   break;
130 }
131
132 return -1;
133}
134
135int     driver_sndio_reopen_device(struct driver_sndio * self);
136ssize_t driver_sndio_write        (struct roar_vio_calls * vio, void *buf, size_t count);
137int     driver_sndio_sync         (struct roar_vio_calls * vio);
138
139int     driver_sndio_ctl          (struct roar_vio_calls * vio, int cmd, void * data) {
140 switch (cmd) {
141  default: return -1;
142 }
143
144 return 0;
145}
146
147#endif
148
149//ll
Note: See TracBrowser for help on using the repository browser.