Search
lxdream.org :: lxdream/src/drivers/audio_pulse.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/audio_pulse.c
changeset 736:a02d1475ccfd
prev710:f6eaa3bcfa5b
next1024:c67f2d61ab97
author nkeynes
date Fri Nov 07 07:53:31 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Fix "0" being confused with "not defined"
view annotate diff log raw
     1 /**
     2  * $Id$
     3  * 
     4  * The pulseaudio sound driver
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     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.
    12  *
    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.
    17  */
    18 #include <stdio.h>
    19 #include <unistd.h>
    20 #include <pulse/simple.h>
    21 #include "aica/audio.h"
    22 #include "lxdream.h"
    24 static pa_simple *pulse_server = NULL;
    26 gboolean audio_pulse_init( )
    27 {
    28     int rate = DEFAULT_SAMPLE_RATE;
    29     int format = DEFAULT_SAMPLE_FORMAT;
    30     pa_sample_spec ss;
    32     if( pulse_server != NULL ) {
    33         pa_simple_free(pulse_server);
    34     }
    35     ss.rate = rate;
    37     if( format & AUDIO_FMT_16BIT ) {
    38         ss.format = PA_SAMPLE_S16NE;
    39     } else {
    40         ss.format = PA_SAMPLE_U8;
    41     }
    43     if( format & AUDIO_FMT_STEREO ) {
    44         ss.channels = 2;
    45     } else {
    46         ss.channels = 1;
    47     }
    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)" );
    53         return FALSE;
    54     }
    55     return TRUE;
    56 }
    58 gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
    59 {
    60     if( pulse_server != NULL ) {
    61         int error;
    62         pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
    63         return TRUE;
    64     } else {
    65         ERROR( "Pulseaudio not initialized" );
    66         return FALSE;
    67     }
    68 }
    70 gboolean audio_pulse_shutdown()
    71 {
    72     pa_simple_free(pulse_server);
    73     pulse_server = NULL;
    74     return TRUE;
    75 }
    77 struct audio_driver audio_pulse_driver = { 
    78         "pulse",
    79         N_("PulseAudio sound server driver"),
    80         DEFAULT_SAMPLE_RATE,
    81         DEFAULT_SAMPLE_FORMAT,
    82         audio_pulse_init,
    83         NULL,
    84         audio_pulse_process_buffer,
    85         NULL,
    86         audio_pulse_shutdown};
.