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 697:479b8c213f61
prev643:653b0a70f173
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@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@66
    24
int esd_handle = -1;
nkeynes@66
    25
int esd_sample_size = 1;
nkeynes@66
    26
bhaal22@643
    27
bhaal22@643
    28
gboolean audio_esd_init()
bhaal22@643
    29
{
nkeynes@697
    30
    int format = DEFAULT_SAMPLE_FORMAT;
nkeynes@697
    31
    int rate = DEFAULT_SAMPLE_RATE;
nkeynes@697
    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@106
    54
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@697
    65
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
bhaal22@643
    72
struct audio_driver audio_esd_driver = { "esd", 
nkeynes@697
    73
        DEFAULT_SAMPLE_RATE,
nkeynes@697
    74
        DEFAULT_SAMPLE_FORMAT,
nkeynes@697
    75
        audio_esd_init,
nkeynes@697
    76
        NULL, 
nkeynes@697
    77
        audio_esd_process_buffer,
nkeynes@697
    78
        NULL,
nkeynes@697
    79
        audio_esd_shutdown};
bhaal22@643
    80
.