Search
lxdream.org :: lxdream/src/drivers/audio_pulse.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/audio_pulse.c
changeset 657:c4143facbfcb
next663:553bb7d6befa
author nkeynes
date Wed Apr 16 10:12:12 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Add support for the pulseaudio sound system
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/drivers/audio_pulse.c Wed Apr 16 10:12:12 2008 +0000
1.3 @@ -0,0 +1,85 @@
1.4 +/**
1.5 + * $Id: audio_pulse.c 661 2008-02-26 01:10:48Z bhaal22 $
1.6 + *
1.7 + * The pulseaudio sound driver
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +#include <stdio.h>
1.22 +#include <unistd.h>
1.23 +#include <pulse/simple.h>
1.24 +#include "aica/audio.h"
1.25 +#include "lxdream.h"
1.26 +
1.27 +static pa_simple *pulse_server = NULL;
1.28 +
1.29 +gboolean audio_pulse_init()
1.30 +{
1.31 + return TRUE;
1.32 +}
1.33 +
1.34 +gboolean audio_pulse_set_format( uint32_t rate, uint32_t format )
1.35 +{
1.36 + pa_sample_spec ss;
1.37 +
1.38 + if( pulse_server != NULL ) {
1.39 + pa_simple_free(pulse_server);
1.40 + }
1.41 + ss.rate = rate;
1.42 +
1.43 + if( format & AUDIO_FMT_16BIT ) {
1.44 + ss.format = PA_SAMPLE_S16NE;
1.45 + } else {
1.46 + ss.format = PA_SAMPLE_U8;
1.47 + }
1.48 +
1.49 + if( format & AUDIO_FMT_STEREO ) {
1.50 + ss.channels = 2;
1.51 + } else {
1.52 + ss.channels = 1;
1.53 + }
1.54 +
1.55 + pulse_server = pa_simple_new(NULL, APP_NAME, PA_STREAM_PLAYBACK,
1.56 + NULL, "Audio", &ss, NULL, NULL, NULL);
1.57 + if( pulse_server == NULL ) {
1.58 + ERROR( "Unable to open audio output (pulseaudio)" );
1.59 + return FALSE;
1.60 + }
1.61 + return TRUE;
1.62 +}
1.63 +
1.64 +gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
1.65 +{
1.66 + if( pulse_server != NULL ) {
1.67 + int error;
1.68 + pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
1.69 + return TRUE;
1.70 + } else {
1.71 + ERROR( "Pulseaudio not initialized" );
1.72 + return FALSE;
1.73 + }
1.74 +}
1.75 +
1.76 +gboolean audio_pulse_close()
1.77 +{
1.78 + pa_simple_free(pulse_server);
1.79 + pulse_server = NULL;
1.80 + return TRUE;
1.81 +}
1.82 +
1.83 +struct audio_driver audio_pulse_driver = { "pulse",
1.84 + audio_pulse_init,
1.85 + audio_pulse_set_format,
1.86 + audio_pulse_process_buffer,
1.87 + audio_pulse_close};
1.88 +
.