source: roaraudio/roard/driver_oss.c @ 924:7f4183d013fa

Last change on this file since 924:7f4183d013fa was 924:7f4183d013fa, checked in by phi, 15 years ago

fixed handling of case the system has OSS support but we found no OSS device, needed for FreeBSD jails

File size: 2.3 KB
Line 
1//driver_oss.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
27
28#define er() close(fh); return -1
29
30int driver_oss_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info) {
31 int tmp;
32 int fh;
33
34#ifdef ROAR_DEFAULT_OSS_DEV
35 if ( device == NULL )
36  device = ROAR_DEFAULT_OSS_DEV;
37#endif
38
39 if ( device == NULL ) {
40  ROAR_ERR("driver_oss_open(*): no default device found, you need to specify one manuelly");
41  return -1;
42 }
43
44 roar_vio_init_calls(inst);
45
46 if ( (fh = open(device, O_WRONLY, 0644)) == -1 ) {
47  ROAR_ERR("driver_oss_open(*): Can not open OSS device: %s: %s", device, strerror(errno));
48  return -1;
49 }
50
51 roar_vio_set_fh(inst, fh);
52
53 switch (info->channels) {
54  case  1: tmp = 0; break;
55  case  2: tmp = 1; break;
56  default: er();
57 }
58
59 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
60  er();
61 }
62
63 switch (info->bits) {
64  case  8: tmp = AFMT_S8; break;
65  case 16:
66    switch (info->codec) {
67     case ROAR_CODEC_PCM_S_LE: tmp = AFMT_S16_LE; break;
68     case ROAR_CODEC_PCM_S_BE: tmp = AFMT_S16_BE; break;
69     default                 : er();
70    }
71   break;
72  default: er();
73 }
74
75 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
76  er();
77 }
78
79 tmp = info->rate;
80
81 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
82  er();
83 }
84
85 if ( tmp < info->rate * 0.98 || tmp > info->rate * 1.02 ) {
86  er();
87 }
88
89 return 0;
90}
91
92int driver_oss_close(DRIVER_USERDATA_T   inst) {
93 return close(roar_vio_get_fh((struct roar_vio_calls *)inst));
94}
95
96
97#endif
98//ll
Note: See TracBrowser for help on using the repository browser.