1 /*
2  * gbsplay is a Gameboy sound player
3  *
4  * 2006 (C) by Tobias Diedrich <ranma+gbsplay@tdiedrich.de>
5  *
6  * Licensed under GNU GPL v1 or, at your option, any later version.
7  */
8 
9 #include "common.h"
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <errno.h>
16 #include <string.h>
17 
18 #include <pulse/error.h>
19 #include <pulse/simple.h>
20 
21 #include "plugout.h"
22 
23 pa_simple *pulse_handle;
24 pa_sample_spec pulse_spec;
25 
pulse_open(enum plugout_endian endian,long rate)26 static long regparm pulse_open(enum plugout_endian endian, long rate)
27 {
28 	int err;
29 
30 	switch (endian) {
31 	case PLUGOUT_ENDIAN_BIG: pulse_spec.format = PA_SAMPLE_S16BE; break;
32 	case PLUGOUT_ENDIAN_LITTLE: pulse_spec.format = PA_SAMPLE_S16LE; break;
33 	case PLUGOUT_ENDIAN_NATIVE: pulse_spec.format = PA_SAMPLE_S16NE; break;
34 	}
35 	pulse_spec.rate = rate;
36 	pulse_spec.channels = 2;
37 
38 	pulse_handle = pa_simple_new(NULL, "gbsplay", PA_STREAM_PLAYBACK, NULL, "gbsplay", &pulse_spec, NULL, NULL, &err);
39 	if (!pulse_handle) {
40 		fprintf(stderr, "pulse: %s\n", pa_strerror(err));
41 		return -1;
42 	}
43 
44 	return 0;
45 }
46 
pulse_write(const void * buf,size_t count)47 static ssize_t regparm pulse_write(const void *buf, size_t count)
48 {
49 	return pa_simple_write(pulse_handle, buf, count, NULL);
50 }
51 
pulse_close()52 static void regparm pulse_close()
53 {
54 	pa_simple_free(pulse_handle);
55 }
56 
57 const struct output_plugin plugout_pulse = {
58 	.name = "pulse",
59 	.description = "PulseAudio sound driver",
60 	.open = pulse_open,
61 	.write = pulse_write,
62 	.close = pulse_close,
63 };
64