1 /*
2 TiMidity++ -- MIDI to WAVE converter and player
3 Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4 Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5
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.
10
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.
15
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 output.h
21
22 */
23
24 #ifndef ___OUTPUT_H_
25 #define ___OUTPUT_H_
26 #include "output.h"
27
28 /* Data format encoding bits */
29 /* {PE_16BIT,PE_ULAW,PE_ALAW} is alternative flag */
30 /* {PE_SIGNED,PE_ULAW,PE_ALAW} is alternative flag */
31 /* {PE_BYTESWAP,PE_ULAW,PE_ALAW} is alternative flag */
32 /* {PE_16BIT,PE_24BIT} is alternative flag */
33 #define PE_MONO (1u<<0) /* versus stereo */
34 #define PE_SIGNED (1u<<1) /* versus unsigned */
35 #define PE_16BIT (1u<<2) /* versus 8-bit */
36 #define PE_ULAW (1u<<3) /* versus linear */
37 #define PE_ALAW (1u<<4) /* versus linear */
38 #define PE_BYTESWAP (1u<<5) /* versus the other way */
39 #define PE_24BIT (1u<<6) /* versus 8-bit, 16-bit */
40
41 /* for play_mode->acntl() */
42 enum {
43 PM_REQ_MIDI, /* ARG: MidiEvent
44 * Send MIDI event.
45 * If PF_MIDI_EVENT is setted, acntl() is called
46 * with this request.
47 */
48
49 PM_REQ_INST_NAME, /* ARG: char**
50 * Get Instrument name of channel.
51 */
52
53 PM_REQ_DISCARD, /* ARG: not-used
54 * Discard the audio device buffer and returns
55 * immediatly.
56 */
57
58 PM_REQ_FLUSH, /* ARG: not-used
59 * Wait until all audio data is out.
60 */
61
62 PM_REQ_GETQSIZ, /* ARG: int
63 * Get maxmum device queue size in bytes.
64 * If acntl() returns -1,
65 * timidity automatically estimate the size
imuldiv8(int32 a,int32 b)66 * using adhoc implementation.
67 * This request is used for trace mode.
68 */
69
70 PM_REQ_SETQSIZ, /* ARG: int (in-out)
71 * Set maxmum device queue size in bytes.
72 * The specified ARG is updated new queue size.
73 */
74
75 PM_REQ_GETFRAGSIZ, /* ARG: int
76 * Get device fragment size in bytes.
77 */
78
79 PM_REQ_RATE, /* ARG: int
80 * Change the sample rate.
81 */
82
83 PM_REQ_GETSAMPLES, /* ARG: int
84 * Get the current play samples.
85 * Play samples must be initialized to zero if
86 * PM_REQ_DISCARD/PM_REQ_FLUSH/PM_REQ_PLAY_START
87 * request is receved.
88 */
89
90 PM_REQ_PLAY_START, /* ARG: not-used
91 * PM_REQ_PLAY_START is called just before playing.
92 */
93
94 PM_REQ_PLAY_END, /* ARG: not-used
95 * PM_REQ_PLAY_END is called just after playing.
96 */
97
98 PM_REQ_GETFILLABLE, /* ARG: int
99 * Get fillable device queue size
100 */
101
102 PM_REQ_GETFILLED, /* ARG: int
103 * Get filled device queue size
104 */
105
106 PM_REQ_OUTPUT_FINISH, /* ARG: not-used
107 * PM_REQ_OUTPUT_FINISH calls just after the last
108 * output_data(), and TiMidity would into
109 * waiting to flush the audio buffer.
110 */
111
112 PM_REQ_DIVISIONS, /* ARG: int32* - pointer to divisions number
113 */
114 };
115
116
117 /* Flag bits */
118 #define PF_PCM_STREAM (1u<<0) /* Enable output PCM data */
119 #define PF_MIDI_EVENT (1u<<1) /* Enable send MIDI event via acntl() */
120 #define PF_CAN_TRACE (1u<<2) /* Enable realtime tracing */
121 #define PF_BUFF_FRAGM_OPT (1u<<3) /* Enable set extra_param[0] to specify
122 the number of audio buffer fragments */
123 #define PF_AUTO_SPLIT_FILE (1u<<4) /* Split PCM files automatically */
124 #define PF_FILE_OUTPUT (1u<<5) /* Output is to file rather than device */
125 #define IS_STREAM_TRACE ((play_mode->flag & (PF_PCM_STREAM|PF_CAN_TRACE)) == (PF_PCM_STREAM|PF_CAN_TRACE))
126
127 typedef struct {
128 int32 rate, encoding, flag;
129 int fd; /* file descriptor for the audio device
130 -1 means closed otherwise opened. It must be -1 by default. */
imuldiv8(int32 a,int32 b)131 int32 extra_param[5]; /* System depended parameters
132 e.g. buffer fragments, ... */
133 char *id_name, id_character;
134 char *name; /* default device or file name */
135 int (* open_output)(void); /* 0=success, 1=warning, -1=fatal error */
136 void (* close_output)(void);
137
138 int (* output_data)(char *buf, int32 bytes);
139 /* return: -1=error, otherwise success */
140
141 int (* acntl)(int request, void *arg); /* see PM_REQ_* above
imuldiv16(int32 a,int32 b)142 * return: 0=success, -1=fail
143 */
144 int (* detect)(void); /* 0=not available, 1=available */
145 } PlayMode;
146
147 extern PlayMode *play_mode_list[], *play_mode;
148 extern PlayMode *target_play_mode;
149 extern int audio_buffer_bits;
150 #define audio_buffer_size (1<<audio_buffer_bits)
151
152 /* Conversion functions -- These overwrite the int32 data in *lp with
imuldiv24(int32 a,int32 b)153 data in another format */
154
155 /* 8-bit signed and unsigned*/
156 extern void s32tos8(int32 *lp, int32 c);
157 extern void s32tou8(int32 *lp, int32 c);
158
159 /* 16-bit */
160 extern void s32tos16(int32 *lp, int32 c);
161 extern void s32tou16(int32 *lp, int32 c);
162
163 /* 24-bit */
imuldiv28(int32 a,int32 b)164 extern void s32tos24(int32 *lp, int32 c);
165 extern void s32tou24(int32 *lp, int32 c);
166
167 /* byte-exchanged 16-bit */
168 extern void s32tos16x(int32 *lp, int32 c);
169 extern void s32tou16x(int32 *lp, int32 c);
170
171 /* uLaw (8 bits) */
172 extern void s32toulaw(int32 *lp, int32 c);
173
174 /* aLaw (8 bits) */
175 extern void s32toalaw(int32 *lp, int32 c);
176
177 extern int32 general_output_convert(int32 *buf, int32 count);
178 extern int validate_encoding(int enc, int include_enc, int exclude_enc);
179 extern int32 apply_encoding(int32 old_enc, int32 new_enc);
180 extern const char *output_encoding_string(int enc);
181 extern int get_encoding_sample_size(int32 enc);
imuldiv8(int32 a,int32 b)182
183 extern char *create_auto_output_name(const char *input_filename, char *ext_str, char *output_dir, int mode);
184
185 #if defined(__W32__)
186 #define FILE_OUTPUT_MODE O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644
187 #elif defined(__MACOS__)
188 #define FILE_OUTPUT_MODE O_WRONLY|O_CREAT|O_TRUNC
189 #else /* UNIX */
190 #define FILE_OUTPUT_MODE O_WRONLY|O_CREAT|O_TRUNC, 0644
191 #endif
192
193 #endif /* ___OUTPUT_H_ */
194
195