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 697:479b8c213f61
prev663:553bb7d6befa
next700:4650d0c7f6f9
author nkeynes
date Sun Jun 22 04:01:27 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Commit work-in-progress CoreAudio driver
(along with various changes to the audio subsystem)
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_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 = { "pulse",
    78         DEFAULT_SAMPLE_RATE,
    79         DEFAULT_SAMPLE_FORMAT,
    80         audio_pulse_init,
    81         NULL,
    82         audio_pulse_process_buffer,
    83         NULL,
    84         audio_pulse_shutdown};
.