OSDN Git Service

Imported UnkoTim211
[timidity41/timidity41.git] / timidity / output.h
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
29
30
31 /* Data format encoding bits */
32 /* {PE_16BIT,PE_ULAW,PE_ALAW} is alternative flag */
33 /* {PE_SIGNED,PE_ULAW,PE_ALAW} is alternative flag */
34 /* {PE_BYTESWAP,PE_ULAW,PE_ALAW} is alternative flag */
35 /* {PE_16BIT,PE_24BIT,PE_32BIT,PE_64BIT,PE_F32BIT,PE_F64BIT} is alternative flag */
36 ///r
37 #define PE_MONO         (1u<<0)  /* versus stereo */
38 #define PE_SIGNED       (1u<<1)  /* versus unsigned */
39 #define PE_BYTESWAP     (1u<<2)  /* versus the other way */
40 #define PE_ULAW         (1u<<3)  /* versus linear */
41 #define PE_ALAW         (1u<<4)  /* versus linear */
42 #define PE_16BIT        (1u<<5)  /* versus 8-bit */
43 #define PE_24BIT        (1u<<6)  /* versus 8-bit, 16-bit */
44 #define PE_32BIT        (1u<<7)  /* versus 8-bit, 16-bit, 24-bit */ // ?
45 #define PE_F32BIT       (1u<<8)  /* versus ? */
46 #define PE_64BIT        (1u<<9)  /* versus 8-bit, 16-bit, 24-bit, 32-bit */ // ?
47 #define PE_F64BIT       (1u<<10)  /* versus ? */
48
49 /* for play_mode->acntl() */
50 enum {
51     PM_REQ_MIDI,        /* ARG: MidiEvent
52                          * Send MIDI event.
53                          * If PF_MIDI_EVENT is setted, acntl() is called
54                          * with this request.
55                          */
56
57     PM_REQ_INST_NAME,   /* ARG: char**
58                          * Get Instrument name of channel.
59                          */
60
61     PM_REQ_DISCARD,     /* ARG: not-used
62                          * Discard the audio device buffer and returns
63                          * immediatly.
64                          */
65
66     PM_REQ_FLUSH,       /* ARG: not-used
67                          * Wait until all audio data is out.
68                          */
69
70     PM_REQ_GETQSIZ,     /* ARG: int
71                          * Get maxmum device queue size in bytes.
72                          * If acntl() returns -1,
73                          * timidity automatically estimate the size
74                          * using adhoc implementation.
75                          * This request is used for trace mode.
76                          */
77
78     PM_REQ_SETQSIZ,     /* ARG: int (in-out)
79                          * Set maxmum device queue size in bytes.
80                          * The specified ARG is updated new queue size.
81                          */
82
83     PM_REQ_GETFRAGSIZ,  /* ARG: int
84                          * Get device fragment size in bytes.
85                          */
86
87     PM_REQ_RATE,        /* ARG: int
88                          * Change the sample rate.
89                          */
90
91     PM_REQ_GETSAMPLES,  /* ARG: int
92                          * Get the current play samples.
93                          * Play samples must be initialized to zero if
94                          * PM_REQ_DISCARD/PM_REQ_FLUSH/PM_REQ_PLAY_START
95                          * request is receved.
96                          */
97
98     PM_REQ_PLAY_START,  /* ARG: not-used
99                          * PM_REQ_PLAY_START is called just before playing.
100                          */
101
102     PM_REQ_PLAY_END,    /* ARG: not-used
103                          * PM_REQ_PLAY_END is called just after playing.
104                          */
105
106     PM_REQ_GETFILLABLE, /* ARG: int
107                          * Get fillable device queue size
108                          */
109
110     PM_REQ_GETFILLED,   /* ARG: int
111                          * Get filled device queue size
112                          */
113
114     PM_REQ_OUTPUT_FINISH, /* ARG: not-used
115                           * PM_REQ_OUTPUT_FINISH calls just after the last
116                           * output_data(), and TiMidity would into
117                           * waiting to flush the audio buffer.
118                           */
119
120     PM_REQ_DIVISIONS,     /* ARG: int32* - pointer to divisions number
121                           */
122 };
123
124
125 /* Flag bits */
126 #define PF_PCM_STREAM   (1u<<0) /* Enable output PCM data */
127 #define PF_MIDI_EVENT   (1u<<1) /* Enable send MIDI event via acntl() */
128 #define PF_CAN_TRACE    (1u<<2) /* Enable realtime tracing */
129 #define PF_BUFF_FRAGM_OPT (1u<<3) /* Enable set extra_param[0] to specify
130                                    the number of audio buffer fragments */
131 #define PF_AUTO_SPLIT_FILE (1u<<4) /* Split PCM files automatically */
132 #define PF_FILE_OUTPUT (1u<<5) /* Output is to file rather than device */
133 #define IS_STREAM_TRACE ((play_mode->flag & (PF_PCM_STREAM|PF_CAN_TRACE)) == (PF_PCM_STREAM|PF_CAN_TRACE))
134
135
136
137 typedef struct {
138     int32 rate;
139     uint32 encoding, flag;
140     int fd; /* file descriptor for the audio device
141                -1 means closed otherwise opened. It must be -1 by default. */
142     int32 extra_param[5]; /* System depended parameters
143                              e.g. buffer fragments, ... */
144     char *id_name, id_character;
145     char *name; /* default device or file name */
146     int (*open_output)(void); /* 0=success, 1=warning, -1=fatal error */
147     void (*close_output)(void);
148
149     int32 (*output_data)(const uint8 *buf, size_t bytes);
150     /* return: -1=error, otherwise success */
151
152     int (*acntl)(int request, void *arg); /* see PM_REQ_* above
153                                             * return: 0=success, -1=fail
154                                             */
155     int (*detect)(void); /* 0=not available, 1=available */
156 } PlayMode;
157
158 extern PlayMode *play_mode_list[], *play_mode;
159 extern PlayMode *target_play_mode;
160 ///r
161 extern int opt_output_device_id;
162 extern int audio_buffer_bits;
163 #define audio_buffer_size       (1<<audio_buffer_bits)
164
165 /* Conversion functions -- These overwrite the int32 data in *lp with
166    data in another format */
167 ///r
168 #if 0
169 /* 8-bit signed and unsigned*/
170 extern void s32tos8(int32 *lp, int32 c);
171 extern void s32tou8(int32 *lp, int32 c);
172
173 /* 16-bit */
174 extern void s32tos16(int32 *lp, int32 c);
175 extern void s32tou16(int32 *lp, int32 c);
176
177 /* 24-bit */
178 extern void s32tos24(int32 *lp, int32 c);
179 extern void s32tou24(int32 *lp, int32 c);
180 ///r
181 /* 32-bit */
182 extern void s32tos32(int32 *lp, int32 c);
183 extern void s32tou32(int32 *lp, int32 c);
184
185 /* float 32-bit */
186 extern void s32tof32(int32 *lp, int32 c);
187
188 /* 64-bit */
189 // extern void s32tos64(int32 *lp, int32 c);
190 // extern void s32tou64(int32 *lp, int32 c);
191
192 /* float 64-bit */
193 // extern void s32tof64(int32 *lp, int32 c);
194
195 /* byte-exchanged 16-bit */
196 extern void s32tos16x(int32 *lp, int32 c);
197 extern void s32tou16x(int32 *lp, int32 c);
198
199 /* uLaw (8 bits) */
200 extern void s32toulaw(int32 *lp, int32 c);
201
202 /* aLaw (8 bits) */
203 extern void s32toalaw(int32 *lp, int32 c);
204 #endif
205
206 ///r
207 extern void general_output_convert_setup(void);
208
209 //extern int32 general_output_convert(int32 *buf, int32 count);
210 extern int32 general_output_convert(DATA_T *buf, int32 count);
211
212 extern int validate_encoding(int enc, int include_enc, int exclude_enc);
213 extern int32 apply_encoding(int32 old_enc, int32 new_enc);
214 extern const char *output_encoding_string(int enc);
215 extern int get_encoding_sample_size(int32 enc);
216
217
218 extern char *create_auto_output_name(const char *input_filename, const char *ext_str, char *output_dir, int mode);
219
220 #if defined(__W32__)
221 #define FILE_OUTPUT_MODE        O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644
222 #elif defined(__MACOS__)
223 #define FILE_OUTPUT_MODE        O_WRONLY|O_CREAT|O_TRUNC
224 #else /* UNIX */
225 #define FILE_OUTPUT_MODE        O_WRONLY|O_CREAT|O_TRUNC, 0644
226 #endif
227
228 extern double div_playmode_rate;
229 extern double playmode_rate_div2;
230 extern double playmode_rate_div3;
231 extern double playmode_rate_div4;
232 extern double playmode_rate_div6;
233 extern double playmode_rate_div8;
234 extern double playmode_rate_ms;
235 extern double playmode_rate_dms;
236 extern double playmode_rate_us;
237 extern void init_output(void);
238 extern void change_output_volume(int32);
239
240 #endif /* ___OUTPUT_H_ */
241