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 643:653b0a70f173
prev561:533f6b478071
next697:479b8c213f61
author bhaal22
date Tue Feb 26 01:10:48 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Commit initial ALSA audio driver
Add init/shutdown stubs to audio driver structure
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
{
bhaal22@643
    30
  return TRUE;
bhaal22@643
    31
}
bhaal22@643
    32
nkeynes@106
    33
gboolean audio_esd_set_format( uint32_t rate, uint32_t format )
nkeynes@66
    34
{
nkeynes@66
    35
    if( esd_handle != -1 ) {
nkeynes@66
    36
	esd_close(esd_handle);
nkeynes@66
    37
    }
nkeynes@66
    38
    esd_format_t esd_format = 0;
nkeynes@66
    39
    esd_sample_size = 1;
nkeynes@66
    40
    if( format & AUDIO_FMT_16BIT ) {
nkeynes@66
    41
	esd_format |= ESD_BITS16;
nkeynes@66
    42
    } else esd_format |= ESD_BITS8;
nkeynes@66
    43
    if( format & AUDIO_FMT_STEREO ) {
nkeynes@66
    44
	esd_format |= ESD_STEREO;
nkeynes@66
    45
    }
nkeynes@66
    46
    else esd_format |= ESD_MONO;
nkeynes@66
    47
    
nkeynes@180
    48
    esd_handle = esd_play_stream( esd_format, rate, "localhost", "lxdream" );
nkeynes@86
    49
    if( esd_handle == -1 ) {
nkeynes@86
    50
	ERROR( "Unable to open audio output (ESD)" );
nkeynes@111
    51
	return FALSE;
nkeynes@86
    52
    }
nkeynes@66
    53
    return TRUE;
nkeynes@66
    54
}
nkeynes@66
    55
nkeynes@106
    56
gboolean audio_esd_process_buffer( audio_buffer_t buffer )
nkeynes@66
    57
{
nkeynes@66
    58
    if( esd_handle != -1 ) {
nkeynes@73
    59
	write( esd_handle, buffer->data, buffer->length );
nkeynes@78
    60
	return TRUE;
nkeynes@66
    61
    } else {
nkeynes@66
    62
	ERROR( "ESD not initialized" );
nkeynes@78
    63
	return FALSE;
nkeynes@66
    64
    }
nkeynes@66
    65
}
nkeynes@66
    66
bhaal22@643
    67
gboolean audio_esd_close()
bhaal22@643
    68
{
bhaal22@643
    69
  return TRUE;
bhaal22@643
    70
}
nkeynes@66
    71
bhaal22@643
    72
struct audio_driver audio_esd_driver = { "esd", 
bhaal22@643
    73
					 audio_esd_init,
bhaal22@643
    74
					 audio_esd_set_format, 
bhaal22@643
    75
					 audio_esd_process_buffer,
bhaal22@643
    76
                                         audio_esd_close};
bhaal22@643
    77
.