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 1024:c67f2d61ab97
prev736:a02d1475ccfd
author nkeynes
date Tue Feb 28 18:22:52 2012 +1000 (12 years ago)
permissions -rw-r--r--
last change Add a GL-only video driver for android usage (since the Java code is
responsible for creating the context)
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 static 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 static 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 static gboolean audio_pulse_shutdown()
    71 {
    72     pa_simple_free(pulse_server);
    73     pulse_server = NULL;
    74     return TRUE;
    75 }
    77 static struct audio_driver audio_pulse_driver = { 
    78         "pulse",
    79         N_("PulseAudio sound server driver"),
    80         10,
    81         DEFAULT_SAMPLE_RATE,
    82         DEFAULT_SAMPLE_FORMAT,
    83         audio_pulse_init,
    84         NULL,
    85         audio_pulse_process_buffer,
    86         NULL,
    87         audio_pulse_shutdown};
    89 AUDIO_DRIVER( "pulse", audio_pulse_driver );
.