2 * This file is part of DisOrder.
3 * Copyright (C) 2013 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /** @file lib/uaudio-pulseaudio.c
19 * @brief Support for PulseAudio backend */
24 #include <pulse/simple.h>
25 #include <pulse/error.h>
30 #include "configuration.h"
32 static const char *const pulseaudio_options[] = {
37 static pa_simple *pulseaudio_simple_handle;
39 /** @brief Open the PulseAudio sound device */
40 static void pulseaudio_open() {
47 ss.format = PA_SAMPLE_U8;
51 ss.format = PA_SAMPLE_S16NE;
55 ss.format = PA_SAMPLE_S32NE;
59 disorder_fatal(0, "unsupported uaudio format (%d, %d)",
60 uaudio_bits, uaudio_signed);
61 ss.channels = uaudio_channels;
62 ss.rate = uaudio_rate;
63 pulseaudio_simple_handle = pa_simple_new(NULL,
64 uaudio_get("application", "DisOrder"),
72 if(!pulseaudio_simple_handle)
73 disorder_fatal(0, "pa_simple_new: %s", pa_strerror(error));
76 /** @brief Close the PulseAudio sound device */
77 static void pulseaudio_close(void) {
78 pa_simple_free(pulseaudio_simple_handle);
79 pulseaudio_simple_handle = NULL;
82 /** @brief Actually play sound via PulseAudio */
83 static size_t pulseaudio_play(void *buffer, size_t samples,
84 unsigned attribute((unused)) flags) {
86 int ret = pa_simple_write(pulseaudio_simple_handle,
88 samples * uaudio_sample_size,
91 disorder_fatal(0, "pa_simple_write: %s", pa_strerror(error));
95 static void pulseaudio_start(uaudio_callback *callback,
98 uaudio_thread_start(callback, userdata, pulseaudio_play,
99 32 / uaudio_sample_size,
100 4096 / uaudio_sample_size,
104 static void pulseaudio_stop(void) {
105 uaudio_thread_stop();
109 static void pulseaudio_open_mixer(void) {
110 disorder_error(0, "no pulseaudio mixer support yet");
113 static void pulseaudio_close_mixer(void) {
116 static void pulseaudio_get_volume(int *left, int *right) {
120 static void pulseaudio_set_volume(int *left, int *right) {
124 static void pulseaudio_configure(void) {
127 const struct uaudio uaudio_pulseaudio = {
128 .name = "pulseaudio",
129 .options = pulseaudio_options,
130 .start = pulseaudio_start,
131 .stop = pulseaudio_stop,
132 .activate = uaudio_thread_activate,
133 .deactivate = uaudio_thread_deactivate,
134 .open_mixer = pulseaudio_open_mixer,
135 .close_mixer = pulseaudio_close_mixer,
136 .get_volume = pulseaudio_get_volume,
137 .set_volume = pulseaudio_set_volume,
138 .configure = pulseaudio_configure,
139 .flags = UAUDIO_API_CLIENT,