OSDN Git Service

Enable 64 bit IO support on MinGW
[timidity41/timidity41.git] / timidity / benchmark_a.c
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     raw_audio.c
21
22     Functions to output raw sound data to a file or stdout.
23
24 */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif /* HAVE_CONFIG_H */
29 #include <stdio.h>
30
31 #ifdef __POCC__
32 #include <sys/types.h>
33 #endif //for off_t
34
35 #ifdef __W32__
36 #include <stdlib.h>
37 #include <io.h>
38 #endif
39
40 #ifdef HAVE_UNISTD_H
41 #include <unistd.h>
42 #endif /* HAVE_UNISTD_H */
43
44 #ifdef STDC_HEADERS
45 #include <stdlib.h>
46 #include <string.h>
47 #include <ctype.h>
48 #elif HAVE_STRINGS_H
49 #include <strings.h>
50 #endif
51
52 #include <fcntl.h>
53
54 #ifdef __FreeBSD__
55 #include <stdio.h>
56 #endif
57
58 #include "timidity.h"
59 #include "common.h"
60 #include "output.h"
61 #include "controls.h"
62 #include "instrum.h"
63 #include "playmidi.h"
64 #include "readmidi.h"
65 #include "timer.h"
66
67 static int open_output(void); /* 0=success, 1=warning, -1=fatal error */
68 static void close_output(void);
69 static int output_data(const uint8 *buf, size_t bytes);
70 static int acntl(int request, void *arg);
71
72 /* export the playback mode */
73
74 #define dpm benchmark_mode
75
76 PlayMode dpm = {
77     DEFAULT_RATE, PE_16BIT|PE_SIGNED, PF_PCM_STREAM|PF_FILE_OUTPUT,
78     -1,
79     {0,0,0,0,0},
80     "Benchmark", 'b',
81     NULL,
82     open_output,
83     close_output,
84     output_data,
85     acntl
86 };
87
88 static double counter = 0.0, time_elapsed = 0.0;
89 static int first = 0;
90
91 /*************************************************************************/
92
93 static int silent_output_open(void)
94 {
95         dpm.flag |= PF_AUTO_SPLIT_FILE;
96         dpm.fd = 1;
97         first = 0;
98         return 0;
99 }
100
101 static int open_output(void)
102 {
103         silent_output_open();
104         return 0;
105 }
106
107 static int output_data(const uint8 *buf, size_t bytes)
108 {
109         if(!bytes)
110                 return bytes;
111         if(first){
112                 time_elapsed = get_current_calender_time() - counter;
113                 return bytes;
114         }
115         first = 1;
116         counter = get_current_calender_time();
117         time_elapsed = 0.0;
118         ctl->cmsg(CMSG_INFO, VERB_NORMAL,
119                 "%s: First output", dpm.id_name);
120         return bytes;
121 }
122
123 static void close_output(void)
124 {
125     if (dpm.fd != -1) {
126         ctl->cmsg(CMSG_INFO, VERB_NORMAL,
127                   "%s: Time elapsed : %.2f sec", dpm.id_name,
128                   (double)(time_elapsed));
129     }
130     dpm.fd = -1;
131         first = 0;
132 }
133
134 static int acntl(int request, void *arg)
135 {
136   switch(request) {
137   case PM_REQ_PLAY_START:
138     if (dpm.flag & PF_AUTO_SPLIT_FILE) {
139       return silent_output_open();
140     }
141     return 0;
142   case PM_REQ_PLAY_END:
143     if(dpm.flag & PF_AUTO_SPLIT_FILE)
144      close_output();
145     return 0;
146   case PM_REQ_DISCARD:
147     return 0;
148   }
149   return -1;
150 }