File: driver_oss.c

package info (click to toggle)
muroard 0.1.14-1
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 420 kB
  • ctags: 424
  • sloc: ansic: 3,645; sh: 505; makefile: 113
file content (129 lines) | stat: -rw-r--r-- 3,198 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//driver_oss.c:

/*
 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013
 *
 *  This file is part of �RoarD,
 *  a sound server daemon for using the RoarAudio protocol.
 *  See README for details.
 *
 *  This file is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  or (at your option) any later version as published by
 *  the Free Software Foundation.
 *
 *  RoarAudio is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this software; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

#include "muroard.h"

#if defined(__OpenBSD__) || defined(__NetBSD__)
#include <soundcard.h>
#else
#include <sys/soundcard.h>
#endif

#include <sys/ioctl.h> /* for ioctl() */

#include <fcntl.h> /* for open() */

#define DRIVER_HAVE_INIT
#define DRIVER_USE_SYSIO

#if defined(MUROARD_FEATURE_DRIVER_OSS_SETFRAGMENT) && defined(SNDCTL_DSP_SETFRAGMENT)
#define driver_set_fragments(x) driver_try_buf_setups((x))
static void driver_try_buf_setups(int fh) {
 unsigned int blocksizes[] = {11, 12, 13};
 unsigned int blocks[]     = {4, 5, 6, 3, 7, 2, 8};
 unsigned int bs, b;
 int tmp;

 for (bs = 0; bs < sizeof(blocksizes)/sizeof(int); bs++) {
  for (b = 0; b  < sizeof(blocks)    /sizeof(int); b++ ) {
   tmp = blocksizes[bs] | (blocks[b] << 16);
   if ( ioctl(fh, SNDCTL_DSP_SETFRAGMENT, &tmp) == 0 )
    return;
  }
 }
}
#else
#define driver_set_fragments(x) ((void)(x))
#endif

#define _err() close(muroard_state_member(driver_fh)); return -1

int muroard_driver_init(const char * dev) {
 int ctmp, tmp;

#ifdef MUROARD_DEFAULT_DRIVER_OSS_DEV
 if ( dev == NULL )
  dev = MUROARD_DEFAULT_DRIVER_OSS_DEV;
#endif

 muroard_state_member(driver_fh) = open(dev, O_WRONLY, 0644);

 if ( muroard_state_member(driver_fh) == -1 )
  return -1;

// channels:
#ifdef SNDCTL_DSP_CHANNELS
 tmp = muroard_state_member(sa_channels);

 if ( ioctl(muroard_state_member(driver_fh), SNDCTL_DSP_CHANNELS, &tmp) == -1 ) {
  _err();
 }

 if ( tmp != muroard_state_member(sa_channels) ) {
  _err();
 }
#else
 switch (muroard_state_member(sa_channels)) {
  case  1: tmp = 0; break;
  case  2: tmp = 1; break;
  default: _err();
 }

 if ( ioctl(muroard_state_member(driver_fh), SNDCTL_DSP_STEREO, &tmp) == -1 ) {
  _err();
 }
#endif

 ctmp = tmp = AFMT_S16_NE;

#ifdef SNDCTL_DSP_SETFMT
 if ( ioctl(muroard_state_member(driver_fh), SNDCTL_DSP_SETFMT, &tmp) == -1 ) {
#else
 if ( ioctl(muroard_state_member(driver_fh), SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) {
#endif
  _err();
 }

 if ( tmp != ctmp ) {
  _err();
 }

 tmp = muroard_state_member(sa_rate);

 if ( ioctl(muroard_state_member(driver_fh), SNDCTL_DSP_SPEED, &tmp) == -1 ) {
  _err();
 }

 if ( tmp != muroard_state_member(sa_rate) ) {
  _err();
 }

 driver_set_fragments(muroard_state_member(driver_fh));

 return 0;
}

//ll