3
TiMidity -- Experimental MIDI to WAVE converter
4
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
Functions to output raw sound data to a file or stdout.
42
#if !defined(OPEN_MODE)
44
#define OPEN_MODE O_WRONLY | O_CREAT | O_TRUNC | O_BINARY
46
#define OPEN_MODE O_WRONLY | O_CREAT | O_TRUNC
50
static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
51
static void close_output(void);
52
static void output_data(int32 *buf, uint32 count);
53
static int driver_output_data(unsigned char *buf, uint32 count);
54
static void flush_output(void);
55
static void purge_output(void);
56
static int output_count(uint32 ct);
58
/* export the playback mode */
62
#define dpm raw_play_mode
65
DEFAULT_RATE, PE_16BIT|PE_SIGNED,
68
"raw waveform data", 'r',
79
/*************************************************************************/
81
static int open_output(void)
83
if (dpm.encoding & PE_ULAW)
84
dpm.encoding &= ~PE_16BIT;
86
if (!(dpm.encoding & PE_16BIT))
87
dpm.encoding &= ~PE_BYTESWAP;
89
if (dpm.name && dpm.name[0]=='-' && dpm.name[1]=='\0')
90
dpm.fd=1; /* data to stdout */
93
/* Open the audio file */
94
dpm.fd=open(dpm.name, OPEN_MODE, 0644);
97
ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
98
dpm.name, sys_errlist[errno]);
105
static int output_count(uint32 ct)
110
static int driver_output_data(unsigned char *buf, uint32 count)
115
static void output_data(int32 *buf, uint32 count)
117
if (!(dpm.encoding & PE_MONO)) count*=2; /* Stereo samples */
119
if (dpm.encoding & PE_16BIT)
121
if (dpm.encoding & PE_BYTESWAP)
123
if (dpm.encoding & PE_SIGNED)
124
s32tos16x(buf, count);
126
s32tou16x(buf, count);
130
if (dpm.encoding & PE_SIGNED)
131
s32tos16(buf, count);
133
s32tou16(buf, count);
136
while ((-1==write(dpm.fd, buf, count * 2)) && errno==EINTR)
141
if (dpm.encoding & PE_ULAW)
143
s32toulaw(buf, count);
147
if (dpm.encoding & PE_SIGNED)
153
while ((-1==write(dpm.fd, buf, count)) && errno==EINTR)
158
static void close_output(void)
160
if (dpm.fd != 1) /* We don't close stdout */
164
static void flush_output(void) { }
165
static void purge_output(void) { }