source: roaraudio/roard/driver_oss.c @ 919:0d97efb0782c

Last change on this file since 919:0d97efb0782c was 919:0d97efb0782c, checked in by phi, 15 years ago

wrote working(!) OSS driver

File size: 2.2 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 if ( device == NULL )
35  device = ROAR_DEFAULT_OSS_DEV;
36
37 roar_vio_init_calls(inst);
38
39 if ( (fh = open(device, O_WRONLY, 0644)) == -1 ) {
40  ROAR_ERR("driver_oss_open(*): Can not open OSS device: %s: %s", device, strerror(errno));
41  return -1;
42 }
43
44 roar_vio_set_fh(inst, fh);
45
46 switch (info->channels) {
47  case  1: tmp = 0; break;
48  case  2: tmp = 1; break;
49  default: er();
50 }
51
52 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
53  er();
54 }
55
56 switch (info->bits) {
57  case  8: tmp = AFMT_S8; break;
58  case 16:
59    switch (info->codec) {
60     case ROAR_CODEC_PCM_S_LE: tmp = AFMT_S16_LE; break;
61     case ROAR_CODEC_PCM_S_BE: tmp = AFMT_S16_BE; break;
62     default                 : er();
63    }
64   break;
65  default: er();
66 }
67
68 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
69  er();
70 }
71
72 tmp = info->rate;
73
74 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
75  er();
76 }
77
78 if ( tmp < info->rate * 0.98 || tmp > info->rate * 1.02 ) {
79  er();
80 }
81
82 return 0;
83}
84
85int driver_oss_close(DRIVER_USERDATA_T   inst) {
86 return close(roar_vio_get_fh((struct roar_vio_calls *)inst));
87}
88
89
90#endif
91//ll
Note: See TracBrowser for help on using the repository browser.