summaryrefslogtreecommitdiff
path: root/audio/libao/patches/patch-ah
blob: f7afe8ee0cba6899f0c5337381f3b3a6ce291b7b (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
$NetBSD: patch-ah,v 1.1 2001/03/20 09:57:37 wiz Exp $

--- src/plugins/sun/ao_sun.c.orig	Mon Mar 19 19:34:22 2001
+++ src/plugins/sun/ao_sun.c
@@ -0,0 +1,150 @@
+/*
+ *
+ *  ao_sun.c    Solaris/NetBSD/OpenBSD
+ *
+ *      Original Copyright (C) Aaron Holtzman - May 1999
+ *      Modifications Copyright (C) Stan Seibert - July 2000
+ *      and Copyright (C) Christian Weisgerber - March 2001
+ *
+ *  libao is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  libao 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 GNU Make; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/audioio.h>
+
+#ifndef AUDIO_ENCODING_SLINEAR
+#define AUDIO_ENCODING_SLINEAR AUDIO_ENCODING_LINEAR	/* Solaris */
+#endif
+
+#include <ao/ao.h>
+
+ao_info_t ao_sun_info = {
+	"Sun audio driver output",
+	"sun",
+	"Christian Weisgerber <naddy@openbsd.org>",
+	"Outputs to the sun audio system."
+};
+
+typedef struct ao_sun_internal_s {
+	char *dev;
+	int fd;
+} ao_sun_internal_t;
+
+void ao_sun_parse_options(ao_sun_internal_t *state, ao_option_t *options)
+{
+	state->dev = NULL;
+
+	while (options) {
+		if (!strcmp(options->key, "dev"))
+			state->dev = strdup(options->value);
+		options = options->next;
+	}
+}
+
+ao_internal_t *plugin_open(uint_32 bits, uint_32 rate, uint_32 channels, ao_option_t *options)
+{
+	ao_sun_internal_t *state;
+	audio_info_t info;
+
+	state = malloc(sizeof(ao_sun_internal_t));
+
+	if (state == NULL) {
+		fprintf(stderr,"libao: Error allocating state memory: %s\n",
+			strerror(errno));
+		goto ERR;
+	}
+
+	ao_sun_parse_options(state, options);
+
+	if (state->dev != NULL) {
+		/* open the user-specified path */
+		state->fd = open(state->dev, O_WRONLY);
+		if (state->fd < 0) {
+			fprintf(stderr, "libao: Error opening audio device %s: %s\n",
+				state->dev, strerror(errno));
+			goto ERR;
+		}
+	} else {
+		/* default */
+		state->dev = strdup("/dev/audio");
+		state->fd = open(state->dev, O_WRONLY);
+		if (state->fd < 0) {
+			fprintf(stderr,
+				"libao: Could not open default device %s: %s\n",
+				state->dev, strerror(errno));
+			goto ERR;
+		}
+	}
+
+	AUDIO_INITINFO(&info);
+#ifdef AUMODE_PLAY	/* NetBSD/OpenBSD */
+	info.mode = AUMODE_PLAY;
+#endif
+	info.play.encoding = AUDIO_ENCODING_SLINEAR;
+	info.play.precision = bits;
+	info.play.sample_rate = rate;
+	info.play.channels = channels;
+
+ 	if (ioctl(state->fd, AUDIO_SETINFO, &info) < 0) {
+		fprintf(stderr,
+			"libao: Cannot set device to %d bits, %d Hz, %d channels: %s\n",
+			bits, rate, channels, strerror(errno));
+		goto ERR;
+	}
+
+	return state;
+
+ERR:
+	if (state != NULL) {
+		if (state->fd >= 0)
+			close(state->fd);
+		if (state->dev)
+			free(state->dev);
+		free(state);
+	}
+	return NULL;
+}
+
+void plugin_play(ao_internal_t *state, void *output_samples, uint_32 num_bytes)
+{
+	write(((ao_sun_internal_t *)state)->fd, output_samples, num_bytes);
+}
+
+void plugin_close(ao_internal_t *state)
+{
+	ao_sun_internal_t *s = (ao_sun_internal_t *)state;
+	close(s->fd);
+	free(s->dev);
+	free(s);
+}
+
+int plugin_get_latency(ao_internal_t *state)
+{
+	/* dummy */
+	return 0;
+}
+
+ao_info_t *plugin_get_driver_info(void)
+{
+	return &ao_sun_info;
+}