3 PROGRAM_NAME PROGRAM_VERSION - PROGRAM_DESCRIPTION
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
58 c
+=(fgetc(f
) * 65536);
59 c
+=(fgetc(f
) * 16777216);
65 int load_sample(FILE * f
, int bits
, int sign
)
77 s|=(((unsigned char)fgetc(f)) << 8);*/
79 s
=(short int)fget16(f
);
88 void load_pcm_wave(FILE * f
, int * size
, int bits
, int channels
,
89 int sign
, int frequency
, int ** lwave
, int ** rwave
)
95 ls
=(int *)malloc(*size
* sizeof(int));
98 rs
=(int *)malloc(*size
* sizeof(int));
102 for(n
=0;n
< *size
;n
++)
104 ls
[n
]=load_sample(f
, bits
, sign
);
107 rs
[n
]=load_sample(f
, bits
, sign
);
110 /* resample if needed */
111 if(frequency
!= _frequency
)
115 ls
=wave_resample(ls
, frequency
, size
);
118 rs
=wave_resample(rs
, frequency
, &n
);
128 int load_wav_file(char * filename
, int * size
, int ** lwave
, int ** rwave
)
133 short int b_per_sec
,num_channels
,tag
;
134 char riffid
[5],waveid
[5],fmtid
[5],dataid
[5];
135 int wav_frequency
, wav_bits
;
139 if((f
=fopen(filename
,"r"))==NULL
)
148 if(strcmp(waveid
,"WAVE"))
163 num_channels
=fget16(f
);
164 wav_frequency
=fget32(f
);
167 wav_bits
=fget16(f
) / num_channels
;
170 fread(dummydata
,1,(size_t)flen
-14,f
);
175 if(wav_bits
==16) (*size
)/=2;
176 if(num_channels
==2) (*size
)/=2;
178 load_pcm_wave(f
, size
, wav_bits
, num_channels
,
179 1, wav_frequency
, &ls
, &rs
);
190 /* table of frequencies for each note */
192 static int _pat_freq_table
[128]=
194 8176, 8662, 9177, 9723,
195 10301, 10913, 11562, 12250,
196 12978, 13750, 14568, 15434,
198 16352, 17324, 18354, 19445,
199 20602, 21827, 23125, 24500,
200 25957, 27500, 29135, 30868,
202 32703, 34648, 36708, 38891,
203 41203, 43654, 46249, 48999,
204 51913, 55000, 58270, 61735,
206 65406, 69296, 73416, 77782,
207 82407, 87307, 92499, 97999,
208 103826, 110000, 116541, 123471,
210 130813, 138591, 146832, 155563,
211 164814, 174614, 184997, 195998,
212 207652, 220000, 233082, 246942,
214 261626, 277183, 293665, 311127,
215 329628, 349228, 369994, 391995,
216 415305, 440000, 466164, 493883,
218 523251, 554365, 587330, 622254,
219 659255, 698456, 739989, 783991,
220 830609, 880000, 932328, 987767,
222 1046502, 1108731, 1174659, 1244508,
223 1318510, 1396913, 1479978, 1567982,
224 1661219, 1760000, 1864655, 1975533,
226 2093005, 2217461, 2349318, 2489016,
227 2637020, 2793826, 2959955, 3135963,
228 3322438, 3520000, 3729310, 3951066,
230 4186009, 4434922, 4698636, 4978032,
231 5274041, 5587652, 5919911, 6271927,
232 6644875, 7040000, 7458620, 7902133,
234 8372018, 8869844, 9397273, 9956063,
235 10548082, 11175303, 11839822, 12543854
239 static int _pat_find_note(int frequency
)
245 if(_pat_freq_table
[n
] >= frequency
)
253 int load_pat_file(char * filename
)
259 int size
, loop_start
, loop_end
;
260 int base_note
, min_note
, max_note
;
261 int frequency
, flags
, bits
, sign
, loop
;
265 if((f
=fopen(filename
,"r"))==NULL
)
268 /* read signatures */
269 fread(buffer
, 12, 1, f
);
270 if(strcmp(buffer
, "GF1PATCH110")!=0)
276 fread(buffer
, 10, 1, f
);
277 if(strcmp(buffer
, "ID#000002")!=0)
283 /* skip description */
284 fread(buffer
, 65, 1, f
);
288 printf("vol: %d\n", i
);
291 fread(buffer
, 109, 1, f
);
295 printf("layers: %d\n", n_layers
);
298 fread(buffer
, 40, 1, f
);
300 for(n
=0;n
< n_layers
;n
++)
303 fread(buffer
, 8, 1, f
);
304 printf("name: '%s'\n", buffer
);
307 loop_start
=fget32(f
);
311 printf("size: %d [%d-%d], freq: %d\n",
312 size
, loop_start
, loop_end
, frequency
);
318 printf("freqs: %d - %d - %d\n",
319 min_note
, base_note
, max_note
);
320 printf("notes: %d - %d - %d\n",
321 _pat_find_note(min_note
),
322 _pat_find_note(base_note
),
323 _pat_find_note(max_note
));
325 /* ignore fine-tune */
330 printf("pan: %d\n", i
);
332 /* skip envelope rate, value, tremolo and vibrato */
333 fread(buffer
, 18, 1, f
);
336 printf("flags: 0x%02X\n", flags
);
338 bits
=flags
& 0x01 ? 16 : 8;
339 sign
=flags
& 0x02 ? 0 : 1;
340 loop
=flags
& 0x04 ? 1 : 0;
342 if(flags
& 8) printf("PINGPONG!!!\n");
344 printf("bits: %d, sign: %d, loop: %d\n",
354 /* skip frequency scale data */
355 fget16(f
); fget16(f
);
358 fread(buffer
, 36, 1, f
);
361 load_pcm_wave(f
, &size
, bits
, 1, sign
,
362 frequency
, &lwave
, &rwave
);
367 q
=fopen("qq.raw", "w");
368 fwrite(lwave
, sizeof(int), size
, q
);