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 657:c4143facbfcb
next663:553bb7d6befa
author nkeynes
date Wed Apr 16 10:12:12 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Add support for the pulseaudio sound system
file annotate diff log raw
nkeynes@657
     1
/**
nkeynes@657
     2
 * $Id: audio_pulse.c 661 2008-02-26 01:10:48Z bhaal22 $
nkeynes@657
     3
 * 
nkeynes@657
     4
 * The pulseaudio sound driver
nkeynes@657
     5
 *
nkeynes@657
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@657
     7
 *
nkeynes@657
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@657
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@657
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@657
    11
 * (at your option) any later version.
nkeynes@657
    12
 *
nkeynes@657
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@657
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@657
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@657
    16
 * GNU General Public License for more details.
nkeynes@657
    17
 */
nkeynes@657
    18
#include <stdio.h>
nkeynes@657
    19
#include <unistd.h>
nkeynes@657
    20
#include <pulse/simple.h>
nkeynes@657
    21
#include "aica/audio.h"
nkeynes@657
    22
#include "lxdream.h"
nkeynes@657
    23
nkeynes@657
    24
static pa_simple *pulse_server = NULL;
nkeynes@657
    25
nkeynes@657
    26
gboolean audio_pulse_init()
nkeynes@657
    27
{
nkeynes@657
    28
  return TRUE;
nkeynes@657
    29
}
nkeynes@657
    30
nkeynes@657
    31
gboolean audio_pulse_set_format( uint32_t rate, uint32_t format )
nkeynes@657
    32
{
nkeynes@657
    33
    pa_sample_spec ss;
nkeynes@657
    34
nkeynes@657
    35
    if( pulse_server != NULL ) {
nkeynes@657
    36
        pa_simple_free(pulse_server);
nkeynes@657
    37
    }
nkeynes@657
    38
    ss.rate = rate;
nkeynes@657
    39
nkeynes@657
    40
    if( format & AUDIO_FMT_16BIT ) {
nkeynes@657
    41
        ss.format = PA_SAMPLE_S16NE;
nkeynes@657
    42
    } else {
nkeynes@657
    43
        ss.format = PA_SAMPLE_U8;
nkeynes@657
    44
    }
nkeynes@657
    45
    
nkeynes@657
    46
    if( format & AUDIO_FMT_STEREO ) {
nkeynes@657
    47
	ss.channels = 2;
nkeynes@657
    48
    } else {
nkeynes@657
    49
        ss.channels = 1;
nkeynes@657
    50
    }
nkeynes@657
    51
nkeynes@657
    52
    pulse_server = pa_simple_new(NULL, APP_NAME, PA_STREAM_PLAYBACK,
nkeynes@657
    53
                                 NULL, "Audio", &ss, NULL, NULL, NULL);
nkeynes@657
    54
    if( pulse_server == NULL ) {
nkeynes@657
    55
	ERROR( "Unable to open audio output (pulseaudio)" );
nkeynes@657
    56
	return FALSE;
nkeynes@657
    57
    }
nkeynes@657
    58
    return TRUE;
nkeynes@657
    59
}
nkeynes@657
    60
nkeynes@657
    61
gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
nkeynes@657
    62
{
nkeynes@657
    63
    if( pulse_server != NULL ) {
nkeynes@657
    64
        int error;
nkeynes@657
    65
        pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
nkeynes@657
    66
	return TRUE;
nkeynes@657
    67
    } else {
nkeynes@657
    68
	ERROR( "Pulseaudio not initialized" );
nkeynes@657
    69
	return FALSE;
nkeynes@657
    70
    }
nkeynes@657
    71
}
nkeynes@657
    72
nkeynes@657
    73
gboolean audio_pulse_close()
nkeynes@657
    74
{
nkeynes@657
    75
  pa_simple_free(pulse_server);
nkeynes@657
    76
  pulse_server = NULL;
nkeynes@657
    77
  return TRUE;
nkeynes@657
    78
}
nkeynes@657
    79
nkeynes@657
    80
struct audio_driver audio_pulse_driver = { "pulse", 
nkeynes@657
    81
					 audio_pulse_init,
nkeynes@657
    82
					 audio_pulse_set_format, 
nkeynes@657
    83
					 audio_pulse_process_buffer,
nkeynes@657
    84
                                         audio_pulse_close};
nkeynes@657
    85
.