source: roaraudio/libroareio/driver_oss.c @ 2132:bc44d4901e33

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

wrote OSS driver, need to test...

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