source: roaraudio/libroareio/driver_oss.c @ 2135:ec80365dd7ef

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

added Debug lions

File size: 2.8 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 if ( dev == NULL )
46  dev = ROAR_DEFAULT_OSS_DEV;
47
48 if ( dev == NULL )
49  return -1;
50
51 ROAR_DBG("roar_cdriver_oss(*) = ?");
52
53 if ( roar_vio_open_file(calls, dev, O_RDWR, 0644) == -1 )
54  return -1;
55
56 if ( roar_vio_ctl(calls, ROAR_VIO_CTL_GET_FH, &fh) == -1 ) {
57  _err();
58 }
59
60// channels:
61#ifdef SNDCTL_DSP_CHANNELS
62 tmp = info->channels;
63
64 if ( ioctl(fh, SNDCTL_DSP_CHANNELS, &tmp) == -1 ) {
65  _err();
66 }
67
68 if ( tmp != info->channels ) {
69  _err();
70 }
71#else
72 switch (info->channels) {
73  case  1: tmp = 0; break;
74  case  2: tmp = 1; break;
75  default: _err();
76 }
77
78 if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) {
79  _err();
80 }
81#endif
82
83// codec/bits:
84 if ( info->codec != ROAR_CODEC_ALAW && info->codec != ROAR_CODEC_MULAW && info->bits != 16 ) {
85  // other modes are currently not supported
86  _err();
87 }
88
89 switch (info->codec) {
90  case ROAR_CODEC_PCM_S_LE:
91   tmp = AFMT_S16_LE;
92  case ROAR_CODEC_PCM_S_BE:
93   tmp = AFMT_S16_BE;
94  case ROAR_CODEC_PCM_U_LE:
95   tmp = AFMT_U16_LE;
96  case ROAR_CODEC_PCM_U_BE:
97   tmp = AFMT_U16_BE;
98   break;
99  case ROAR_CODEC_ALAW:
100    tmp = AFMT_A_LAW;
101   break;
102  case ROAR_CODEC_MULAW:
103    tmp = AFMT_MU_LAW;
104   break;
105 }
106
107 ctmp = tmp;
108#ifdef SNDCTL_DSP_SETFMT
109 if ( ioctl(fh, SNDCTL_DSP_SETFMT, &tmp) == -1 ) {
110#else
111 if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
112#endif
113  _err();
114 }
115
116 if ( tmp != ctmp ) {
117  _err();
118 }
119
120// rate:
121 tmp = info->rate;
122
123 if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) {
124  _err();
125 }
126
127 if ( tmp != info->rate ) {
128  _err();
129 }
130
131 return 0;
132}
133
134#endif
135
136//ll
Note: See TracBrowser for help on using the repository browser.