2 * $Id: audio_pulse.c 661 2008-02-26 01:10:48Z bhaal22 $
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()
31 gboolean audio_pulse_set_format( uint32_t rate, uint32_t format )
35 if( pulse_server != NULL ) {
36 pa_simple_free(pulse_server);
40 if( format & AUDIO_FMT_16BIT ) {
41 ss.format = PA_SAMPLE_S16NE;
43 ss.format = PA_SAMPLE_U8;
46 if( format & AUDIO_FMT_STEREO ) {
52 pulse_server = pa_simple_new(NULL, APP_NAME, PA_STREAM_PLAYBACK,
53 NULL, "Audio", &ss, NULL, NULL, NULL);
54 if( pulse_server == NULL ) {
55 ERROR( "Unable to open audio output (pulseaudio)" );
61 gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
63 if( pulse_server != NULL ) {
65 pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
68 ERROR( "Pulseaudio not initialized" );
73 gboolean audio_pulse_close()
75 pa_simple_free(pulse_server);
80 struct audio_driver audio_pulse_driver = { "pulse",
82 audio_pulse_set_format,
83 audio_pulse_process_buffer,
.