-
Notifications
You must be signed in to change notification settings - Fork 21
/
plugout_pulse.c
64 lines (52 loc) · 1.48 KB
/
plugout_pulse.c
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
/*
* gbsplay is a Gameboy sound player
*
* 2006-2020 (C) by Tobias Diedrich <[email protected]>
*
* Licensed under GNU GPL v1 or, at your option, any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <pulse/error.h>
#include <pulse/simple.h>
#include "common.h"
#include "plugout.h"
static pa_simple *pulse_handle;
static pa_sample_spec pulse_spec;
static long pulse_open(enum plugout_endian *endian, long rate, long *buffer_bytes, const struct plugout_metadata metadata)
{
int err;
UNUSED(buffer_bytes);
switch (*endian) {
case PLUGOUT_ENDIAN_BIG: pulse_spec.format = PA_SAMPLE_S16BE; break;
case PLUGOUT_ENDIAN_LITTLE: pulse_spec.format = PA_SAMPLE_S16LE; break;
default: pulse_spec.format = PA_SAMPLE_S16NE; break;
}
pulse_spec.rate = rate;
pulse_spec.channels = 2;
pulse_handle = pa_simple_new(NULL, metadata.player_name, PA_STREAM_PLAYBACK, NULL, metadata.filename, &pulse_spec, NULL, NULL, &err);
if (!pulse_handle) {
fprintf(stderr, "pulse: %s\n", pa_strerror(err));
return -1;
}
return 0;
}
static ssize_t pulse_write(const void *buf, size_t count)
{
return pa_simple_write(pulse_handle, buf, count, NULL);
}
static void pulse_close()
{
pa_simple_free(pulse_handle);
}
const struct output_plugin plugout_pulse = {
.name = "pulse",
.description = "PulseAudio sound driver",
.open = pulse_open,
.write = pulse_write,
.close = pulse_close,
};