source: roaraudio/libroareio/driver_oss.c @ 5270:e25346c13638

Last change on this file since 5270:e25346c13638 was 5270:e25346c13638, checked in by phi, 12 years ago

fixed some gcc -Wextra warnings

File size: 4.2 KB
Line 
1//driver_oss.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27#include "driver.h"
28
29#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
30
31#if defined(__OpenBSD__) || defined(__NetBSD__)
32#include <soundcard.h>
33#else
34#include <sys/soundcard.h>
35#endif
36#include <sys/ioctl.h>
37
38#ifdef SNDCTL_DSP_SETFRAGMENT
39static void roar_cdriver_oss_try_buf_setups(struct roar_vio_calls * calls) {
40 struct roar_vio_sysio_ioctl ctl;
41 int blocksizes[] = {11, 12, 13};
42 int blocks[]     = {4, 5, 6, 3, 7, 2, 8};
43 size_t bs, b;
44 int tmp;
45
46 ctl.cmd  = SNDCTL_DSP_SETFRAGMENT;
47 ctl.argp = &tmp;
48
49 for (bs = 0; bs < sizeof(blocksizes)/sizeof(int); bs++) {
50  for (b = 0; b  < sizeof(blocks)    /sizeof(int); b++ ) {
51   tmp = blocksizes[bs] | (blocks[b] << 16);
52   if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == 0 )
53    return;
54  }
55 }
56}
57#endif
58
59#define _err() roar_vio_close(calls); return -1
60
61int roar_cdriver_oss(struct roar_vio_calls * calls, const char * name, const char * dev, struct roar_audio_info * info, int dir) {
62 struct roar_vio_defaults def;
63 struct roar_vio_sysio_ioctl ctl;
64 int tmp, ctmp;
65
66 (void)name;
67
68 // preinit ctl struct, we always pass ints in tmp.
69 ctl.argp = &tmp;
70
71 ROAR_DBG("roar_cdriver_oss(*) = ?");
72
73#ifdef ROAR_DEFAULT_OSS_DEV
74 if ( dev == NULL )
75  dev = ROAR_DEFAULT_OSS_DEV;
76#endif
77
78 if ( dev == NULL )
79  return -1;
80
81 ROAR_DBG("roar_cdriver_oss(*) = ?");
82
83 switch (dir) {
84  case ROAR_DIR_PLAY:
85  case ROAR_DIR_MONITOR:
86  case ROAR_DIR_OUTPUT:
87    tmp = O_WRONLY;
88   break;
89  case ROAR_DIR_BIDIR:
90    tmp = O_RDWR;
91   break;
92  case ROAR_DIR_RECORD:
93    tmp = O_RDONLY;
94   break;
95  default:
96    return -1;
97 }
98
99 ROAR_DBG("roar_cdriver_oss(*) = ?");
100
101 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, tmp, 0644) == -1 )
102   return -1;
103
104 if ( roar_vio_open_dstr(calls, dev, &def, 1) == -1 )
105   return -1;
106
107// channels:
108#ifdef SNDCTL_DSP_CHANNELS
109 tmp = info->channels;
110
111 ctl.cmd  = SNDCTL_DSP_CHANNELS;
112
113 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
114  _err();
115 }
116
117 if ( tmp != (int)info->channels ) {
118  _err();
119 }
120#else
121 switch (info->channels) {
122  case  1: tmp = 0; break;
123  case  2: tmp = 1; break;
124  default: _err();
125 }
126
127 ctl.cmd = SNDCTL_DSP_STEREO;
128
129 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
130  _err();
131 }
132#endif
133
134// codec/bits:
135 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
136  // other modes are currently not supported
137  _err();
138 }
139
140 switch (info->codec) {
141  case ROAR_CODEC_PCM_S_LE:
142    tmp = AFMT_S16_LE;
143   break;
144  case ROAR_CODEC_PCM_S_BE:
145    tmp = AFMT_S16_BE;
146   break;
147  case ROAR_CODEC_PCM_U_LE:
148    tmp = AFMT_U16_LE;
149   break;
150  case ROAR_CODEC_PCM_U_BE:
151    tmp = AFMT_U16_BE;
152   break;
153  case ROAR_CODEC_ALAW:
154    tmp = AFMT_A_LAW;
155   break;
156  case ROAR_CODEC_MULAW:
157    tmp = AFMT_MU_LAW;
158   break;
159  default:
160    _err();
161 }
162
163 ctmp = tmp;
164#ifdef SNDCTL_DSP_SETFMT
165 ctl.cmd = SNDCTL_DSP_SETFMT;
166#else
167 ctl.cmd = SNDCTL_DSP_SAMPLESIZE;
168#endif
169
170 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
171  _err();
172 }
173
174 if ( tmp != ctmp ) {
175  _err();
176 }
177
178// rate:
179 tmp = info->rate;
180
181 ctl.cmd = SNDCTL_DSP_SPEED;
182 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_SYSIO_IOCTL, &ctl) == -1 ) {
183  _err();
184 }
185
186 if ( tmp != (int)info->rate ) {
187  _err();
188 }
189
190#ifdef SNDCTL_DSP_SETFRAGMENT
191 roar_cdriver_oss_try_buf_setups(calls);
192#endif
193
194 return 0;
195}
196
197#endif
198
199//ll
Note: See TracBrowser for help on using the repository browser.