source: roaraudio/libroareio/driver_oss.c @ 2217:903e0d660b29

Last change on this file since 2217:903e0d660b29 was 2217:903e0d660b29, checked in by phi, 15 years ago

in case we do not know a OSS default device

File size: 3.2 KB
Line 
1//driver_oss.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *
6 *  This file is part of roarclients 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 <roaraudio.h>
26#include "driver.h"
27
28#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
29
30#if defined(__OpenBSD__) || defined(__NetBSD__)
31#include <soundcard.h>
32#else
33#include <sys/soundcard.h>
34#endif
35#include <sys/ioctl.h>
36
37#define _err() roar_vio_close(calls); return -1
38
39int roar_cdriver_oss(struct roar_vio_calls * calls, char * name, char * dev, struct roar_audio_info * info, int dir) {
40 int fh;
41 int tmp, ctmp;
42
43 ROAR_DBG("roar_cdriver_oss(*) = ?");
44
45#ifdef ROAR_DEFAULT_OSS_DEV
46 if ( dev == NULL )
47  dev = ROAR_DEFAULT_OSS_DEV;
48#endif
49
50 if ( dev == NULL )
51  return -1;
52
53 ROAR_DBG("roar_cdriver_oss(*) = ?");
54
55 switch (dir) {
56  case ROAR_DIR_PLAY:
57  case ROAR_DIR_MONITOR:
58  case ROAR_DIR_OUTPUT:
59    tmp = O_WRONLY;
60   break;
61  case ROAR_DIR_BIDIR:
62    tmp = O_RDWR;
63   break;
64  case ROAR_DIR_RECORD:
65    tmp = O_RDONLY;
66  default:
67    return -1;
68 }
69
70 if ( roar_vio_open_file(calls, dev, tmp, 0644) == -1 )
71  return -1;
72
73 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) {
74  _err();
75 }
76
77// channels:
78#ifdef SNDCTL_DSP_CHANNELS
79 tmp = info->channels;
80
81 if ( ioctl(fh, SNDCTL_DSP_CHANNELS, &tmp) == -1 ) {
82  _err();
83 }
84
85 if ( tmp != info->channels ) {
86  _err();
87 }
88#else
89 switch (info->channels) {
90  case  1: tmp = 0; break;
91  case  2: tmp = 1; break;
92  default: _err();
93 }
94
95 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
96  _err();
97 }
98#endif
99
100// codec/bits:
101 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
102  // other modes are currently not supported
103  _err();
104 }
105
106 switch (info->codec) {
107  case ROAR_CODEC_PCM_S_LE:
108    tmp = AFMT_S16_LE;
109   break;
110  case ROAR_CODEC_PCM_S_BE:
111    tmp = AFMT_S16_BE;
112   break;
113  case ROAR_CODEC_PCM_U_LE:
114    tmp = AFMT_U16_LE;
115   break;
116  case ROAR_CODEC_PCM_U_BE:
117    tmp = AFMT_U16_BE;
118   break;
119  case ROAR_CODEC_ALAW:
120    tmp = AFMT_A_LAW;
121   break;
122  case ROAR_CODEC_MULAW:
123    tmp = AFMT_MU_LAW;
124   break;
125  default:
126    _err();
127 }
128
129 ctmp = tmp;
130#ifdef SNDCTL_DSP_SETFMT
131 if ( ioctl(fh, SNDCTL_DSP_SETFMT, &tmp) == -1 ) {
132#else
133 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
134#endif
135  _err();
136 }
137
138 if ( tmp != ctmp ) {
139  _err();
140 }
141
142// rate:
143 tmp = info->rate;
144
145 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
146  _err();
147 }
148
149 if ( tmp != info->rate ) {
150  _err();
151 }
152
153 return 0;
154}
155
156#endif
157
158//ll
Note: See TracBrowser for help on using the repository browser.