source: roaraudio/libroareio/driver_oss.c @ 3516:2becb65c23b6

Last change on this file since 3516:2becb65c23b6 was 2569:6997f3702901, checked in by phi, 15 years ago

try out some settings for the sound card blocking, not a good way of doing it, but should work

File size: 3.7 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#ifdef SNDCTL_DSP_SETFRAGMENT
38static void roar_cdriver_oss_try_buf_setups(int fh) {
39 int blocksizes[] = {11, 12, 13};
40 int blocks[]     = {4, 5, 6, 3, 7, 2, 8};
41 int bs, b;
42 int tmp;
43
44 for (bs = 0; bs < sizeof(blocksizes)/sizeof(int); bs++) {
45  for (b = 0; b  < sizeof(blocks)    /sizeof(int); b++ ) {
46   tmp = blocksizes[bs] | (blocks[b] << 16);
47   if ( ioctl(fh, SNDCTL_DSP_SETFRAGMENT, &tmp) == 0 )
48    return;
49  }
50 }
51}
52#endif
53
54#define _err() roar_vio_close(calls); return -1
55
56int roar_cdriver_oss(struct roar_vio_calls * calls, char * name, char * dev, struct roar_audio_info * info, int dir) {
57 int fh;
58 int tmp, ctmp;
59
60 ROAR_DBG("roar_cdriver_oss(*) = ?");
61
62#ifdef ROAR_DEFAULT_OSS_DEV
63 if ( dev == NULL )
64  dev = ROAR_DEFAULT_OSS_DEV;
65#endif
66
67 if ( dev == NULL )
68  return -1;
69
70 ROAR_DBG("roar_cdriver_oss(*) = ?");
71
72 switch (dir) {
73  case ROAR_DIR_PLAY:
74  case ROAR_DIR_MONITOR:
75  case ROAR_DIR_OUTPUT:
76    tmp = O_WRONLY;
77   break;
78  case ROAR_DIR_BIDIR:
79    tmp = O_RDWR;
80   break;
81  case ROAR_DIR_RECORD:
82    tmp = O_RDONLY;
83   break;
84  default:
85    return -1;
86 }
87
88 ROAR_DBG("roar_cdriver_oss(*) = ?");
89
90 if ( roar_vio_open_file(calls, dev, tmp, 0644) == -1 )
91  return -1;
92
93 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) {
94  _err();
95 }
96
97// channels:
98#ifdef SNDCTL_DSP_CHANNELS
99 tmp = info->channels;
100
101 if ( ioctl(fh, SNDCTL_DSP_CHANNELS, &tmp) == -1 ) {
102  _err();
103 }
104
105 if ( tmp != info->channels ) {
106  _err();
107 }
108#else
109 switch (info->channels) {
110  case  1: tmp = 0; break;
111  case  2: tmp = 1; break;
112  default: _err();
113 }
114
115 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
116  _err();
117 }
118#endif
119
120// codec/bits:
121 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
122  // other modes are currently not supported
123  _err();
124 }
125
126 switch (info->codec) {
127  case ROAR_CODEC_PCM_S_LE:
128    tmp = AFMT_S16_LE;
129   break;
130  case ROAR_CODEC_PCM_S_BE:
131    tmp = AFMT_S16_BE;
132   break;
133  case ROAR_CODEC_PCM_U_LE:
134    tmp = AFMT_U16_LE;
135   break;
136  case ROAR_CODEC_PCM_U_BE:
137    tmp = AFMT_U16_BE;
138   break;
139  case ROAR_CODEC_ALAW:
140    tmp = AFMT_A_LAW;
141   break;
142  case ROAR_CODEC_MULAW:
143    tmp = AFMT_MU_LAW;
144   break;
145  default:
146    _err();
147 }
148
149 ctmp = tmp;
150#ifdef SNDCTL_DSP_SETFMT
151 if ( ioctl(fh, SNDCTL_DSP_SETFMT, &tmp) == -1 ) {
152#else
153 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
154#endif
155  _err();
156 }
157
158 if ( tmp != ctmp ) {
159  _err();
160 }
161
162// rate:
163 tmp = info->rate;
164
165 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
166  _err();
167 }
168
169 if ( tmp != info->rate ) {
170  _err();
171 }
172
173#ifdef SNDCTL_DSP_SETFRAGMENT
174 roar_cdriver_oss_try_buf_setups(fh);
175#endif
176
177 return 0;
178}
179
180#endif
181
182//ll
Note: See TracBrowser for help on using the repository browser.