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 663:553bb7d6befa
prev657:c4143facbfcb
next697:479b8c213f61
author nkeynes
date Fri Jun 20 05:43:34 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Cocoa: Don't try to display the error dialog if the gui isn't running
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   return TRUE;
    29 }
    31 gboolean audio_pulse_set_format( uint32_t rate, uint32_t format )
    32 {
    33     pa_sample_spec ss;
    35     if( pulse_server != NULL ) {
    36         pa_simple_free(pulse_server);
    37     }
    38     ss.rate = rate;
    40     if( format & AUDIO_FMT_16BIT ) {
    41         ss.format = PA_SAMPLE_S16NE;
    42     } else {
    43         ss.format = PA_SAMPLE_U8;
    44     }
    46     if( format & AUDIO_FMT_STEREO ) {
    47 	ss.channels = 2;
    48     } else {
    49         ss.channels = 1;
    50     }
    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)" );
    56 	return FALSE;
    57     }
    58     return TRUE;
    59 }
    61 gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
    62 {
    63     if( pulse_server != NULL ) {
    64         int error;
    65         pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
    66 	return TRUE;
    67     } else {
    68 	ERROR( "Pulseaudio not initialized" );
    69 	return FALSE;
    70     }
    71 }
    73 gboolean audio_pulse_close()
    74 {
    75   pa_simple_free(pulse_server);
    76   pulse_server = NULL;
    77   return TRUE;
    78 }
    80 struct audio_driver audio_pulse_driver = { "pulse", 
    81 					 audio_pulse_init,
    82 					 audio_pulse_set_format, 
    83 					 audio_pulse_process_buffer,
    84                                          audio_pulse_close};
.