4 * The pulseaudio sound driver
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <pulse/simple.h>
21 #include "aica/audio.h"
24 static pa_simple *pulse_server = NULL;
26 gboolean audio_pulse_init( )
28 int rate = DEFAULT_SAMPLE_RATE;
29 int format = DEFAULT_SAMPLE_FORMAT;
32 if( pulse_server != NULL ) {
33 pa_simple_free(pulse_server);
37 if( format & AUDIO_FMT_16BIT ) {
38 ss.format = PA_SAMPLE_S16NE;
40 ss.format = PA_SAMPLE_U8;
43 if( format & AUDIO_FMT_STEREO ) {
49 pulse_server = pa_simple_new(NULL, APP_NAME, PA_STREAM_PLAYBACK,
50 NULL, "Audio", &ss, NULL, NULL, NULL);
51 if( pulse_server == NULL ) {
52 ERROR( "Unable to open audio output (pulseaudio)" );
58 gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
60 if( pulse_server != NULL ) {
62 pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
65 ERROR( "Pulseaudio not initialized" );
70 gboolean audio_pulse_shutdown()
72 pa_simple_free(pulse_server);
77 struct audio_driver audio_pulse_driver = {
79 N_("PulseAudio sound server driver"),
81 DEFAULT_SAMPLE_FORMAT,
84 audio_pulse_process_buffer,
86 audio_pulse_shutdown};
.