comparison pmd_play.c @ 5:c4218fbe158f

Fix indent in pmd_play.c.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 21 May 2013 13:30:32 +0200
parents c8875256b767
children
comparison
equal deleted inserted replaced
4:c8875256b767 5:c4218fbe158f
105 uchar musbuf[mdata_def*1024]; 105 uchar musbuf[mdata_def*1024];
106 106
107 if((fd = open(filename, O_RDONLY)) < 0) { 107 if((fd = open(filename, O_RDONLY)) < 0) {
108 return ERR_OPEN_MUSIC_FILE; 108 return ERR_OPEN_MUSIC_FILE;
109 } 109 }
110 110
111 size = read(fd, musbuf, sizeof(musbuf)); 111 size = read(fd, musbuf, sizeof(musbuf));
112 close(fd); 112 close(fd);
113 result = music_load3(musbuf, size); 113 result = music_load3(musbuf, size);
114 return result; 114 return result;
115 } 115 }
116 #endif 116 #endif
117 117
118 static void usage(char *argv0) { 118 static void usage(char *argv0) {
119 const char *usage_str = 119 const char *usage_str =
120 "%s [-f <output file>] [-l <loop count>] [-m <device mask>] [-c <channel mask>] [-t <time>] [-r <samplerate>] <PMD File>\n\ 120 "%s [-f <output file>] [-l <loop count>] [-m <device mask>] [-c <channel mask>] [-t <time>] [-r <samplerate>] <PMD File>\n\
121 -f - Write output to wavfile\n\ 121 -f - Write output to wavfile\n\
122 -l - Loop n times (default is once - use 0 for infinite loop)\n\ 122 -l - Loop n times (default is once - use 0 for infinite loop)\n\
123 -m - Device mask: 1 - OPNA, 2 - PSG, 4 - Rhythm (or them together)\n\ 123 -m - Device mask: 1 - OPNA, 2 - PSG, 4 - Rhythm (or them together)\n\
124 -c - Channel mask: 1,2,4,8,16,32 are OPNA channels 1-6, 64,128,256 are PSG channels 1-3. Once again, or them together\n\ 124 -c - Channel mask: 1,2,4,8,16,32 are OPNA channels 1-6, 64,128,256 are PSG channels 1-3. Once again, or them together\n\
137 char pmd_compo[1024]; 137 char pmd_compo[1024];
138 #if defined(WIN32) || defined(WIN64) 138 #if defined(WIN32) || defined(WIN64)
139 HWAVEOUT hWaveOut; 139 HWAVEOUT hWaveOut;
140 #endif 140 #endif
141 char buf[1024]; 141 char buf[1024];
142 pmdwininit(); 142 pmdwininit();
143 143
144 while((opt = getopt(argc, argv, "f:l:m:c:t:r:")) != -1) { 144 while((opt = getopt(argc, argv, "f:l:m:c:t:r:")) != -1) {
145 switch(opt) { 145 switch(opt) {
146 case 'f': 146 case 'f':
147 tofile = 1; 147 tofile = 1;
158 setdevmask(atoui((uint8_t*)optarg)); 158 setdevmask(atoui((uint8_t*)optarg));
159 break; 159 break;
160 case 't': 160 case 't':
161 pmd_length = atoui((uint8_t*)optarg)*1000; 161 pmd_length = atoui((uint8_t*)optarg)*1000;
162 break; 162 break;
163 case 'r': 163 case 'r':
164 samplerate_out = atoui((uint8_t*)optarg); 164 samplerate_out = atoui((uint8_t*)optarg);
165 break; 165 break;
166 default: 166 default:
167 usage(argv[0]); 167 usage(argv[0]);
168 return 1; 168 return 1;
169 } 169 }
170 } 170 }
172 if(!tofile) { 172 if(!tofile) {
173 #if defined(WIN32) || defined(WIN64) 173 #if defined(WIN32) || defined(WIN64)
174 if(!wave_out_open(&hWaveOut, samplerate_out, 1)) { 174 if(!wave_out_open(&hWaveOut, samplerate_out, 1)) {
175 #else 175 #else
176 #ifdef USE_ALSA 176 #ifdef USE_ALSA
177 if((out_fd = alsa_audio_open(&samplerate_out, 1, NULL, 0)) < 0) { 177 if((out_fd = alsa_audio_open(&samplerate_out, 1, NULL, 0)) < 0) {
178 #else 178 #else
179 if((out_fd = oss_audio_open(samplerate_out, 1)) < 0) { 179 if((out_fd = oss_audio_open(samplerate_out, 1)) < 0) {
180 #endif 180 #endif
181 #endif 181 #endif
182 fprintf(stderr, "Cannot open sound device, exiting.\n"); 182 fprintf(stderr, "Cannot open sound device, exiting.\n");
198 SetConsoleOutputCP(65001); // UTF-8 198 SetConsoleOutputCP(65001); // UTF-8
199 #endif 199 #endif
200 printf("Title = %s\n", pmd_title); 200 printf("Title = %s\n", pmd_title);
201 getmemo3(pmd_compo, NULL, 0, 2); 201 getmemo3(pmd_compo, NULL, 0, 2);
202 printf("Composer = %s\n", pmd_compo); 202 printf("Composer = %s\n", pmd_compo);
203 setpcmrate(samplerate_out); 203 setpcmrate(samplerate_out);
204 music_start(); 204 music_start();
205 i = 0; 205 i = 0;
206 if(pmd_length != 0) { 206 if(pmd_length != 0) {
207 frameno = lrintf(((float)pmd_length*(float)samplerate_out)/(4096.0f*1000.0f)); 207 frameno = lrintf(((float)pmd_length*(float)samplerate_out)/(4096.0f*1000.0f));
208 } else { 208 } else {
220 #endif 220 #endif
221 #ifdef USE_ALSA 221 #ifdef USE_ALSA
222 if(!tofile) { 222 if(!tofile) {
223 j = snd_pcm_writei(out_fd, pcmbuf, 2048); 223 j = snd_pcm_writei(out_fd, pcmbuf, 2048);
224 if(j == -EPIPE) { 224 if(j == -EPIPE) {
225 snd_pcm_prepare(out_fd); 225 snd_pcm_prepare(out_fd);
226 } 226 }
227 } else 227 } else
228 #endif 228 #endif
229 write(out_fd, pcmbuf, 8192); 229 write(out_fd, pcmbuf, 8192);
230 i++; 230 i++;
234 if(!tofile) { 234 if(!tofile) {
235 wave_out_close(hWaveOut); 235 wave_out_close(hWaveOut);
236 } else 236 } else
237 #endif 237 #endif
238 #ifdef USE_ALSA 238 #ifdef USE_ALSA
239 alsa_audio_close(out_fd); 239 alsa_audio_close(out_fd);
240 #else 240 #else
241 close(out_fd); 241 close(out_fd);
242 #endif 242 #endif
243 return 0; 243 return 0;
244 } 244 }