source: roaraudio/libroareio/driver_oss.c @ 2301:a3f4186896b3

Last change on this file since 2301:a3f4186896b3 was 2301:a3f4186896b3, checked in by phi, 15 years ago

debug lion and missing break

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   break;
67  default:
68    return -1;
69 }
70
71 ROAR_DBG("roar_cdriver_oss(*) = ?");
72
73 if ( roar_vio_open_file(calls, dev, tmp, 0644) == -1 )
74  return -1;
75
76 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) {
77  _err();
78 }
79
80// channels:
81#ifdef SNDCTL_DSP_CHANNELS
82 tmp = info->channels;
83
84 if ( ioctl(fh, SNDCTL_DSP_CHANNELS, &tmp) == -1 ) {
85  _err();
86 }
87
88 if ( tmp != info->channels ) {
89  _err();
90 }
91#else
92 switch (info->channels) {
93  case  1: tmp = 0; break;
94  case  2: tmp = 1; break;
95  default: _err();
96 }
97
98 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
99  _err();
100 }
101#endif
102
103// codec/bits:
104 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
105  // other modes are currently not supported
106  _err();
107 }
108
109 switch (info->codec) {
110  case ROAR_CODEC_PCM_S_LE:
111    tmp = AFMT_S16_LE;
112   break;
113  case ROAR_CODEC_PCM_S_BE:
114    tmp = AFMT_S16_BE;
115   break;
116  case ROAR_CODEC_PCM_U_LE:
117    tmp = AFMT_U16_LE;
118   break;
119  case ROAR_CODEC_PCM_U_BE:
120    tmp = AFMT_U16_BE;
121   break;
122  case ROAR_CODEC_ALAW:
123    tmp = AFMT_A_LAW;
124   break;
125  case ROAR_CODEC_MULAW:
126    tmp = AFMT_MU_LAW;
127   break;
128  default:
129    _err();
130 }
131
132 ctmp = tmp;
133#ifdef SNDCTL_DSP_SETFMT
134 if ( ioctl(fh, SNDCTL_DSP_SETFMT, &tmp) == -1 ) {
135#else
136 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
137#endif
138  _err();
139 }
140
141 if ( tmp != ctmp ) {
142  _err();
143 }
144
145// rate:
146 tmp = info->rate;
147
148 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
149  _err();
150 }
151
152 if ( tmp != info->rate ) {
153  _err();
154 }
155
156 return 0;
157}
158
159#endif
160
161//ll
Note: See TracBrowser for help on using the repository browser.