Search
lxdream.org :: lxdream/src/drivers/audio_esd.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/audio_esd.c
changeset 1024:c67f2d61ab97
prev736:a02d1475ccfd
author nkeynes
date Sat Jun 13 00:50:48 2009 +0000 (13 years ago)
permissions -rw-r--r--
last change Build drivers with library dependencies as shared objects (ie plugins)
file annotate diff log raw
nkeynes@66
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@66
     3
 * 
nkeynes@66
     4
 * The esd (esound) audio driver
nkeynes@66
     5
 *
nkeynes@66
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@66
     7
 *
nkeynes@66
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@66
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@66
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@66
    11
 * (at your option) any later version.
nkeynes@66
    12
 *
nkeynes@66
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@66
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@66
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@66
    16
 * GNU General Public License for more details.
nkeynes@66
    17
 */
nkeynes@424
    18
#include <stdio.h>
nkeynes@424
    19
#include <unistd.h>
nkeynes@66
    20
#include <esd.h>
nkeynes@66
    21
#include "aica/audio.h"
nkeynes@66
    22
#include "dream.h"
nkeynes@66
    23
nkeynes@1024
    24
static int esd_handle = -1;
nkeynes@1024
    25
static int esd_sample_size = 1;
nkeynes@66
    26
bhaal22@643
    27
nkeynes@1024
    28
static gboolean audio_esd_init()
bhaal22@643
    29
{
nkeynes@697
    30
    int format = DEFAULT_SAMPLE_FORMAT;
nkeynes@697
    31
    int rate = DEFAULT_SAMPLE_RATE;
nkeynes@736
    32
nkeynes@66
    33
    if( esd_handle != -1 ) {
nkeynes@697
    34
        esd_close(esd_handle);
nkeynes@66
    35
    }
nkeynes@66
    36
    esd_format_t esd_format = 0;
nkeynes@66
    37
    esd_sample_size = 1;
nkeynes@66
    38
    if( format & AUDIO_FMT_16BIT ) {
nkeynes@697
    39
        esd_format |= ESD_BITS16;
nkeynes@66
    40
    } else esd_format |= ESD_BITS8;
nkeynes@66
    41
    if( format & AUDIO_FMT_STEREO ) {
nkeynes@697
    42
        esd_format |= ESD_STEREO;
nkeynes@66
    43
    }
nkeynes@66
    44
    else esd_format |= ESD_MONO;
nkeynes@697
    45
nkeynes@180
    46
    esd_handle = esd_play_stream( esd_format, rate, "localhost", "lxdream" );
nkeynes@86
    47
    if( esd_handle == -1 ) {
nkeynes@697
    48
        ERROR( "Unable to open audio output (ESD)" );
nkeynes@697
    49
        return FALSE;
nkeynes@86
    50
    }
nkeynes@66
    51
    return TRUE;
nkeynes@66
    52
}
nkeynes@66
    53
nkeynes@1024
    54
static gboolean audio_esd_process_buffer( audio_buffer_t buffer )
nkeynes@66
    55
{
nkeynes@66
    56
    if( esd_handle != -1 ) {
nkeynes@697
    57
        write( esd_handle, buffer->data, buffer->length );
nkeynes@697
    58
        return TRUE;
nkeynes@66
    59
    } else {
nkeynes@697
    60
        ERROR( "ESD not initialized" );
nkeynes@697
    61
        return FALSE;
nkeynes@66
    62
    }
nkeynes@66
    63
}
nkeynes@66
    64
nkeynes@1024
    65
static gboolean audio_esd_shutdown()
bhaal22@643
    66
{
nkeynes@697
    67
    close(esd_handle);
nkeynes@697
    68
    esd_handle = -1;
nkeynes@697
    69
    return TRUE;
bhaal22@643
    70
}
nkeynes@66
    71
nkeynes@1024
    72
static struct audio_driver audio_esd_driver = { 
nkeynes@700
    73
        "esd",
nkeynes@700
    74
        N_("Enlightened Sound Daemon driver"),
nkeynes@1024
    75
        30,
nkeynes@697
    76
        DEFAULT_SAMPLE_RATE,
nkeynes@697
    77
        DEFAULT_SAMPLE_FORMAT,
nkeynes@697
    78
        audio_esd_init,
nkeynes@697
    79
        NULL, 
nkeynes@697
    80
        audio_esd_process_buffer,
nkeynes@697
    81
        NULL,
nkeynes@697
    82
        audio_esd_shutdown};
bhaal22@643
    83
nkeynes@1024
    84
AUDIO_DRIVER( "esd", audio_esd_driver );
.