3
TiMidity++ -- MIDI to WAVE converter and player
4
Copyright (C) 1999 Masanao Izumo <mo@goice.co.jp>
5
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
esd_a.c by Avatar <avatar@deva.net>
24
Functions to play sound through EsounD
32
#endif /* HAVE_CONFIG_H */
63
#include "miditrace.h"
67
static int acntl(int request, void *arg);
69
static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
70
static void close_output(void);
71
static void output_data(int32 *buf, uint32 count);
72
static int driver_output_data(unsigned char *buf, uint32 count);
73
static void flush_output(void);
74
static void purge_output(void);
75
static int output_count(uint32 ct);
77
/* export the playback mode */
79
#define dpm esd_play_mode
85
PF_PCM_STREAM|PF_CAN_TRACE|PF_BUFF_FRAGM_OPT,
87
{0}, /* default: get all the buffer fragments you can */
88
"Enlightened sound daemon", 'e',
100
{0}, /* default: get all the buffer fragments you can */
101
"Enlightened sound daemon", 'e',
115
/*************************************************************************/
116
/* We currently only honor the PE_MONO bit, and the sample rate. */
118
static int open_output(void)
120
int fd, /*tmp, i,*/ warnings = 0;
121
/* int include_enc, exclude_enc; */
122
esd_format_t esdformat;
126
exclude_enc = PE_ULAW|PE_ALAW|PE_BYTESWAP; /* They can't mean these */
127
if(dpm.encoding & PE_16BIT)
128
include_enc |= PE_SIGNED;
130
exclude_enc |= PE_SIGNED;
131
dpm.encoding = validate_encoding(dpm.encoding, include_enc, exclude_enc);
134
/* Open the audio device */
135
esdformat = (dpm.encoding & PE_16BIT) ? ESD_BITS16 : ESD_BITS8;
136
esdformat |= (dpm.encoding & PE_MONO) ? ESD_MONO : ESD_STEREO;
137
fd = esd_play_stream_fallback(esdformat,dpm.rate,NULL,"timidity");
140
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
141
dpm.name, strerror(errno));
151
static int driver_output_data(unsigned char *buf, uint32 count)
153
return write(dpm.fd, buf, count);
157
static int output_data(char *buf, uint32 count)
163
if((n = write(dpm.fd, buf, count)) == -1)
165
ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,
166
"%s: %s", dpm.name, strerror(errno));
167
if(errno == EWOULDBLOCK)
169
/* It is possible to come here because of bug of the
186
static int output_count(uint32 ct)
189
int samples_queued = 0, samples_sent = (int)ct;
190
extern int b_out_count();
192
samples = samples_sent = b_out_count();
195
/* samples_queued is PM_REQ_GETFILLED */
197
if (snd_pcm_playback_status(handle, &playback_status) == 0)
198
samples_queued = playback_status.queue;
200
samples -= samples_queued;
202
if (!(dpm.encoding & PE_MONO)) samples >>= 1;
203
if (dpm.encoding & PE_16BIT) samples >>= 1;
207
static void output_data(int32 *buf, uint32 count)
211
if (!(dpm.encoding & PE_MONO)) count*=2; /* Stereo samples */
215
if (dpm.encoding & PE_16BIT)
217
/* Convert data to signed 16-bit PCM */
218
s32tos16(buf, count);
223
/* Convert to 8-bit unsigned and write out. */
228
b_out(dpm.id_character, dpm.fd, (int *)buf, ocount);
232
static void flush_output(void)
238
static void purge_output(void)
240
b_out(dpm.id_character, dpm.fd, 0, -1);
246
static void close_output(void)
255
static int acntl(int request, void *arg)
264
/* not implemented yet */