2 * Copyright 2004-2005 Timo Hirvonen
4 * sun.c by alex <pukpuk@gmx.de>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
24 #include <sys/audioio.h>
34 static sample_format_t sun_sf
;
35 static int sun_fd
= -1;
37 static char *sun_audio_device
= NULL
;
39 static int sun_reset(void)
41 if (ioctl(sun_fd
, AUDIO_FLUSH
, NULL
) == -1)
47 static int sun_set_sf(sample_format_t sf
)
49 struct audio_info ainf
;
51 AUDIO_INITINFO(&ainf
);
56 ainf
.play
.channels
= sf_get_channels(sun_sf
);
57 ainf
.play
.sample_rate
= sf_get_rate(sun_sf
);
59 ainf
.mode
= AUMODE_PLAY
;
61 switch (sf_get_bits(sun_sf
)) {
63 ainf
.play
.precision
= 16;
64 if (sf_get_signed(sun_sf
)) {
65 if (sf_get_bigendian(sun_sf
))
66 ainf
.play
.encoding
= AUDIO_ENCODING_SLINEAR_BE
;
68 ainf
.play
.encoding
= AUDIO_ENCODING_SLINEAR_LE
;
70 if (sf_get_bigendian(sun_sf
))
71 ainf
.play
.encoding
= AUDIO_ENCODING_ULINEAR_BE
;
73 ainf
.play
.encoding
= AUDIO_ENCODING_ULINEAR_LE
;
77 ainf
.play
.precision
= 8;
78 if (sf_get_signed(sun_sf
))
79 ainf
.play
.encoding
= AUDIO_ENCODING_SLINEAR
;
81 ainf
.play
.encoding
= AUDIO_ENCODING_ULINEAR
;
87 if (ioctl(sun_fd
, AUDIO_SETINFO
, &ainf
) == -1)
90 if (ioctl(sun_fd
, AUDIO_GETINFO
, &ainf
) == -1)
93 /* FIXME: check if sample rate is supported */
97 static int sun_device_exists(const char *dev
)
106 static int sun_init(void)
108 const char *audio_dev
= "/dev/audio";
110 if (sun_audio_device
!= NULL
) {
111 if (sun_device_exists(sun_audio_device
))
113 free(sun_audio_device
);
114 sun_audio_device
= NULL
;
117 if (sun_device_exists(audio_dev
)) {
118 sun_audio_device
= xstrdup(audio_dev
);
125 static int sun_exit(void)
127 if (sun_audio_device
!= NULL
) {
128 free(sun_audio_device
);
129 sun_audio_device
= NULL
;
135 static int sun_open(sample_format_t sf
)
137 sun_fd
= open(sun_audio_device
, O_WRONLY
);
140 if (sun_set_sf(sf
) == -1) {
148 static int sun_close(void)
158 static int sun_write(const char *buf
, int cnt
)
166 int rc
= write(sun_fd
, buf
, cnt
);
180 static int sun_pause(void)
182 struct audio_info ainf
;
184 AUDIO_INITINFO(&ainf
);
187 if (ioctl(sun_fd
, AUDIO_SETINFO
, &ainf
) == -1)
193 static int sun_unpause(void)
195 struct audio_info ainf
;
197 AUDIO_INITINFO(&ainf
);
200 if (ioctl(sun_fd
, AUDIO_SETINFO
, &ainf
) == -1)
206 static int sun_buffer_space(void)
208 struct audio_info ainf
;
211 AUDIO_INITINFO(&ainf
);
213 if (ioctl(sun_fd
, AUDIO_GETINFO
, &ainf
) == -1)
215 sp
= ainf
.play
.buffer_size
;
220 static int op_sun_set_option(int key
, const char *val
)
224 free(sun_audio_device
);
225 sun_audio_device
= xstrdup(val
);
228 return -OP_ERROR_NOT_OPTION
;
234 static int op_sun_get_option(int key
, char **val
)
238 if (sun_audio_device
)
239 *val
= xstrdup(sun_audio_device
);
242 return -OP_ERROR_NOT_OPTION
;
248 const struct output_plugin_ops op_pcm_ops
= {
255 .unpause
= sun_unpause
,
256 .buffer_space
= sun_buffer_space
,
257 .set_option
= op_sun_set_option
,
258 .get_option
= op_sun_get_option
261 const char * const op_pcm_options
[] = {
266 const int op_priority
= 0;