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)
file annotate diff log raw
nkeynes@657
     1
/**
nkeynes@663
     2
 * $Id$
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@697
    26
gboolean audio_init( )
nkeynes@657
    27
{
nkeynes@697
    28
    int rate = DEFAULT_SAMPLE_RATE;
nkeynes@697
    29
    int format = DEFAULT_SAMPLE_FORMAT;
nkeynes@657
    30
    pa_sample_spec ss;
nkeynes@657
    31
nkeynes@657
    32
    if( pulse_server != NULL ) {
nkeynes@657
    33
        pa_simple_free(pulse_server);
nkeynes@657
    34
    }
nkeynes@657
    35
    ss.rate = rate;
nkeynes@657
    36
nkeynes@657
    37
    if( format & AUDIO_FMT_16BIT ) {
nkeynes@657
    38
        ss.format = PA_SAMPLE_S16NE;
nkeynes@657
    39
    } else {
nkeynes@657
    40
        ss.format = PA_SAMPLE_U8;
nkeynes@657
    41
    }
nkeynes@657
    42
    
nkeynes@657
    43
    if( format & AUDIO_FMT_STEREO ) {
nkeynes@657
    44
	ss.channels = 2;
nkeynes@657
    45
    } else {
nkeynes@657
    46
        ss.channels = 1;
nkeynes@657
    47
    }
nkeynes@657
    48
nkeynes@657
    49
    pulse_server = pa_simple_new(NULL, APP_NAME, PA_STREAM_PLAYBACK,
nkeynes@657
    50
                                 NULL, "Audio", &ss, NULL, NULL, NULL);
nkeynes@657
    51
    if( pulse_server == NULL ) {
nkeynes@657
    52
	ERROR( "Unable to open audio output (pulseaudio)" );
nkeynes@657
    53
	return FALSE;
nkeynes@657
    54
    }
nkeynes@657
    55
    return TRUE;
nkeynes@657
    56
}
nkeynes@657
    57
nkeynes@657
    58
gboolean audio_pulse_process_buffer( audio_buffer_t buffer )
nkeynes@657
    59
{
nkeynes@657
    60
    if( pulse_server != NULL ) {
nkeynes@657
    61
        int error;
nkeynes@657
    62
        pa_simple_write( pulse_server, buffer->data, buffer->length, &error );
nkeynes@657
    63
	return TRUE;
nkeynes@657
    64
    } else {
nkeynes@657
    65
	ERROR( "Pulseaudio not initialized" );
nkeynes@657
    66
	return FALSE;
nkeynes@657
    67
    }
nkeynes@657
    68
}
nkeynes@657
    69
nkeynes@697
    70
gboolean audio_pulse_shutdown()
nkeynes@657
    71
{
nkeynes@657
    72
  pa_simple_free(pulse_server);
nkeynes@657
    73
  pulse_server = NULL;
nkeynes@657
    74
  return TRUE;
nkeynes@657
    75
}
nkeynes@657
    76
nkeynes@697
    77
struct audio_driver audio_pulse_driver = { "pulse",
nkeynes@697
    78
        DEFAULT_SAMPLE_RATE,
nkeynes@697
    79
        DEFAULT_SAMPLE_FORMAT,
nkeynes@697
    80
        audio_pulse_init,
nkeynes@697
    81
        NULL,
nkeynes@697
    82
        audio_pulse_process_buffer,
nkeynes@697
    83
        NULL,
nkeynes@697
    84
        audio_pulse_shutdown};
nkeynes@657
    85
.