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 111:230243c2b520
prev106:9048bac046c3
next180:e6dcf9b65658
author nkeynes
date Thu Mar 16 12:41:59 2006 +0000 (15 years ago)
permissions -rw-r--r--
last change Handle driver-unable-to-init case
file annotate diff log raw
nkeynes@66
     1
/**
nkeynes@111
     2
 * $Id: audio_esd.c,v 1.7 2006-03-16 12:41:56 nkeynes Exp $
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@66
    18
#include <esd.h>
nkeynes@66
    19
#include "aica/audio.h"
nkeynes@66
    20
#include "dream.h"
nkeynes@66
    21
nkeynes@66
    22
int esd_handle = -1;
nkeynes@66
    23
int esd_sample_size = 1;
nkeynes@66
    24
nkeynes@106
    25
gboolean audio_esd_set_format( uint32_t rate, uint32_t format )
nkeynes@66
    26
{
nkeynes@66
    27
    if( esd_handle != -1 ) {
nkeynes@66
    28
	esd_close(esd_handle);
nkeynes@66
    29
    }
nkeynes@66
    30
    esd_format_t esd_format = 0;
nkeynes@66
    31
    esd_sample_size = 1;
nkeynes@66
    32
    if( format & AUDIO_FMT_16BIT ) {
nkeynes@66
    33
	esd_format |= ESD_BITS16;
nkeynes@66
    34
    } else esd_format |= ESD_BITS8;
nkeynes@66
    35
    if( format & AUDIO_FMT_STEREO ) {
nkeynes@66
    36
	esd_format |= ESD_STEREO;
nkeynes@66
    37
    }
nkeynes@66
    38
    else esd_format |= ESD_MONO;
nkeynes@66
    39
    
nkeynes@66
    40
    esd_handle = esd_play_stream( esd_format, rate, "localhost", "dreamon" );
nkeynes@86
    41
    if( esd_handle == -1 ) {
nkeynes@86
    42
	ERROR( "Unable to open audio output (ESD)" );
nkeynes@111
    43
	return FALSE;
nkeynes@86
    44
    }
nkeynes@66
    45
    return TRUE;
nkeynes@66
    46
}
nkeynes@66
    47
nkeynes@106
    48
gboolean audio_esd_process_buffer( audio_buffer_t buffer )
nkeynes@66
    49
{
nkeynes@66
    50
    if( esd_handle != -1 ) {
nkeynes@73
    51
	write( esd_handle, buffer->data, buffer->length );
nkeynes@78
    52
	return TRUE;
nkeynes@66
    53
    } else {
nkeynes@66
    54
	ERROR( "ESD not initialized" );
nkeynes@78
    55
	return FALSE;
nkeynes@66
    56
    }
nkeynes@66
    57
}
nkeynes@66
    58
nkeynes@106
    59
struct audio_driver audio_esd_driver = { "esd", audio_esd_set_format, audio_esd_process_buffer };
nkeynes@66
    60
.