1 
2 
3 
4 #include "config.h"
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include "main.h"
10 #include "mod.h"
11 
12 
13 #ifdef GUS
14 #include <machine/ultrasound.h>
15 #include "gus.h"
16 #endif /* GUS */
17 
18 
19 const char voice_mk[] = "M.K.";
20 const char voice_mk2[] = "M!K!";
21 const char voice_mk3[] = "M&K!";
22 const char voice_flt4[] = "FLT4";
23 const char voice_flt8[] = "FLT8";
24 const char voice_8chn[] = "8CHN";
25 const char voice_6chn[] = "6CHN";
26 
27 const char *voice_31_list[] =
28 {
29   voice_mk, voice_mk2, voice_mk3, voice_flt4, voice_flt8, voice_8chn,
30   voice_6chn, NULL
31 };
32 
33 int8 normal_vol_adj[65] =
34 {
35    0,   1,   2,   3,   4,   5,   6,   7,
36    8,   9,  10,  11,  12,  13,  14,  15,
37   16,  17,  18,  19,  20,  21,  22,  23,
38   24,  25,  26,  27,  28,  29,  30,  31,
39   32,  33,  34,  35,  36,  37,  38,  39,
40   40,  41,  42,  43,  44,  45,  46,  47,
41   48,  49,  50,  51,  52,  53,  54,  55,
42   56,  57,  58,  59,  60,  61,  62,  63,
43   63
44 };
45 
46 int8 loud_vol_adj[65] =
47 {
48    0,   0,   1,   2,   2,   3,   3,   4,
49    5,   6,   7,   8,   9,  10,  12,  14,
50   16,  18,  20,  22,  24,  26,  28,  30,
51   32,  34,  36,  38,  40,  42,  44,  46,
52   47,  48,  49,  50,  51,  52,  53,  53,
53   54,  55,  55,  56,  56,  57,  57,  58,
54   58,  59,  59,  60,  60,  61,  61,  61,
55   62,  62,  62,  63,  63,  63,  63,  63,
56   63
57 };
58 
59 uint8 sintable[] =
60 {
61    0,25,50,74,98,120,142,162,180,197,212,225,
62    236,244,250,254,255,254,250,244,236,225,
63    212,197,180,162,142,120,98,74,50,25
64 };
65 
66 uint16 period_set[] =
67   {
68       0x06B0,0x0650,0x05F5,0x05A0,0x054F,0x0503,0x04BB,0x0477,0x0436,0x03FA,0x03C1,0x038B  ,
69       0x0358,0x0328,0x02FB,0x02D0,0x02A7,0x0281,0x025D,0x023B,0x021B,0x01FD,0x01E0,0x01C5  ,
70       0x01AC,0x0194,0x017D,0x0168,0x0154,0x0141,0x012F,0x011E,0x010E,0x00FE,0x00F0,0x00E3  ,
71       0x00D6,0x00CA,0x00BF,0x00B4,0x00AA,0x00A0,0x0097,0x008F,0x0087,0x007F,0x0078,0x0071  ,
72       0x006B,0x0065,0x005F,0x005A,0x0055,0x0050,0x004C,0x0047,0x0043,0x0040,0x003C,0x0039  ,
73       0x0035,0x0032,0x0030,0x002D,0x002A,0x0028,0x0026,0x0024,0x0022,0x0020,0x001E,0x001C  ,
74       0x001B,0x0019,0x0018,0x0016,0x0015,0x0014,0x0013,0x0012,0x0011,0x0010,0x000F,0x000E
75   };
76 
77 uint16 period_set_step[] =
78 {
79     0x0680,0x0622,0x05CA,0x0577,0x0529,0x04DF,0x0499,0x0456,0x0418,0x03DD,0x03A6,0x0371,
80     0x0340,0x0311,0x02E5,0x02BB,0x0294,0x026F,0x024C,0x022B,0x020C,0x01EE,0x01D2,0x01B8,
81     0x01A0,0x0188,0x0172,0x015E,0x014A,0x0138,0x0126,0x0116,0x0106,0x00F7,0x00E9,0x00DC,
82     0x00D0,0x00C4,0x00B9,0x00AF,0x00A5,0x009B,0x0093,0x008B,0x0083,0x007B,0x0074,0x006E,
83     0x0068,0x0062,0x005C,0x0057,0x0052,0x004E,0x0049,0x0045,0x0041,0x003E,0x003A,0x0037,
84     0x0033,0x0031,0x002E,0x002B,0x0029,0x0027,0x0025,0x0023,0x0021,0x001F,0x001D,0x001B,
85     0x001A,0x0018,0x0017,0x0015,0x0014,0x0013,0x0012,0x0011,0x0010,0x000F,0x000E,0x000E
86 };
87 
88 song_data               mod;
89 uint8                   order_pos;
90 uint8                   tempo;
91 uint8                   tempo_wait;
92 uint8                   bpm;
93 uint8                   row;
94 uint8                   break_row;
95 uint16                  bpm_samples;
96 uint8                  *buf_ptr;
97 uint16                  buf_len;
98 uint16                  buf_rep;
99 pattern_ptr             note;
100 track_info              tracks[MAX_TRACKS];
101 track_info              old_tracks[MAX_TRACKS];
102 uint32                  mixspeed = 22000;
103 int16                   mod_done;
104 uint8                   loop_mod = 1;
105 
106 union vol_union vol;
107 
beattrack(register track_info_ptr track)108 void beattrack(register track_info_ptr track)
109 {
110 
111   /* Quick FIX */
112   if (track->period_low_limit==0)
113      track->period_low_limit=1;
114 
115   track->playing_volume = track->volume;
116   track->playing_period = track->period;
117 
118   if (track->effect & EFF_VOL_SLIDE)
119   {
120     track->volume += track->vol_slide;
121     if (track->volume < 0) track->volume = 0;
122     if (track->volume > 64) track->volume = 64;
123 
124     track->playing_volume = track->volume;
125   }
126 
127 
128   if (track->effect & EFF_PORT_DOWN)
129   {
130     /* Portamento Down */
131     if ((track->period += track->port_down) > track->period_high_limit)
132       track->period = track->period_high_limit;
133     if (track->period != 0)
134       track->pitch = track->finetune_rate / track->period;
135     else
136       track->pitch = 1;
137     track->playing_period = track->period;
138   }
139 
140   if (track->effect & EFF_PORT_UP)
141   {
142     /* Portamento Up */
143     if ((track->period -= track->port_up) < track->period_low_limit)
144     {
145       if (mod.s3m)
146          track->period = track->period_high_limit;
147          else
148          track->period = track->period_low_limit;
149     }
150     track->pitch = track->finetune_rate / track->period;
151 
152     track->playing_period = track->period;
153   }
154 
155   if (track->effect & EFF_PORT_TO)
156   {
157     if (track->portto < track->period)
158     {
159       if ((track->period += track->port_inc) > track->portto)
160         track->period = track->portto;
161     } else if (track->portto > track->period)
162     {
163       if ((track->period -= track->port_inc) < track->portto)
164         track->period = track->portto;
165     }
166     track->pitch = track->finetune_rate / track->period;
167     track->playing_period = track->period;
168   }
169 
170 
171   if (track->effect & EFF_VIBRATO)
172   {
173     /* Vibrato */
174     track->vibpos += (track->vib_rate) << 2;
175     track->playing_period =
176       ((uint16)sintable[(track->vibpos >> 2) & 0x1F] *
177          (track->vib_depth)) >> 7;
178     if (track->vibpos & 0x80)
179       track->playing_period = -track->playing_period;
180     track->playing_period += track->period;
181     if (track->playing_period < track->period_low_limit)
182       track->playing_period = track->period_low_limit;
183     if (track->playing_period > track->period_high_limit)
184       track->playing_period = track->period_high_limit;
185     track->pitch = track->finetune_rate / track->playing_period;
186   }
187   if (track->effect & EFF_ARPEGGIO)
188   {
189     /* Arpeggio */
190     track->pitch = track->finetune_rate / track->arp[track->arpindex];
191     track->playing_period = track->arp[track->arpindex++];
192     if (track->arpindex >= 3)
193       track->arpindex = 0;
194   }
195 /* if (track->effect & EFF_TREMOLO)
196   {
197     track->trempos += (track->trem_rate) >> 2;
198     t =  ((uint16)sintable[(track->trempos >> 2) & 0x1F] *
199          (track->trem_depth)) >> 7;
200     if (track->trempos & 0x80) t = -t;
201     t = track->volume;
202     if (t < 0) t = 0;
203     if (t > 63) t = 63;
204     track->volume = t;
205   }
206   if (track->effect & EFF_RETRIG)
207   {
208     if (tempo_wait == track->retrig)
209       track->position = 0;
210     track->note_hit = 1;
211 
212   } */
213 }
214 
get_track(register track_info_ptr track,pattern_ptr * pattern)215 void get_track(register track_info_ptr track, pattern_ptr *pattern)
216 {
217   uint8 sample = *(*pattern) & 0xF0;
218   uint16 period;
219   uint8 effect;
220   uint8 param;
221   int16 i;
222 
223   period = (uint16)((*(*pattern)++) & 0x0F) << 8;
224   period |= *(*pattern)++;
225   effect = *(*pattern) & 0x0F;
226   sample |= (*(*pattern)++ & 0xF0) >> 4;
227   param = *(*pattern)++;
228   track->effect = 0;
229 
230   if (sample)
231   {
232     sample--;
233     track->samp = sample;
234     track->volume = mod.volume[sample];
235     track->length = mod.sample_length[sample];
236     track->repeat = mod.repeat_point[sample];
237     track->replen = mod.repeat_length[sample];
238     track->finetune_rate = mod.finetune_rate[sample];
239     track->samples = mod.samples[sample];
240     track->period_low_limit = mod.period_low_limit[sample];
241     track->period_high_limit = mod.period_high_limit[sample];
242   }
243   if (period)
244   {
245     track->portto = period;
246     if ((effect != 3) && (effect != 5))
247     {
248       track->start_period = track->period = period;
249       track->pitch = track->finetune_rate / period;
250       track->position = 0;
251       track->note_hit = 1;
252     }
253   }
254   if ((effect) || (param))
255   {
256 #ifdef DEBUG
257     printf("effect %02X param %02X period %02X track %p\n",
258             effect,param,period,track);
259 #endif
260     switch (effect)
261     {
262       /* Set the three periodtable amounts for each */
263       /* half note pitch for arpeggio */
264       case 0: for (i=12;i<48;i++)
265                  if (track->period >= period_set[i]) break;
266               track->arp[0] = period_set[i];
267               track->arp[1] = period_set[i+(param & 0x0F)];
268               track->arp[2] = period_set[i+((param & 0xF0) >> 4)];
269               track->arpindex = 0;
270 	      track->effect |= EFF_ARPEGGIO;
271               break;
272       case 1: track->effect |= EFF_PORT_UP;
273 	      if (param)
274                  track->port_up = param;
275 	      break;
276       case 2: track->effect |= EFF_PORT_DOWN;
277 	      if (param)
278                  track->port_down = param;
279 	      break;
280       /* Sets up portamento to for new note */
281       case 3: if (param)
282 	         track->port_inc = param;
283 	      track->effect |= EFF_PORT_TO;
284               break;
285       /* Initialize vibrato effect */
286       case 4: if (param & 0x0F)
287 	           track->vib_depth = param & 0x0F;
288               if (param & 0xF0)
289 	           track->vib_rate = (param & 0xF0) >> 4;
290               if (period)
291                    track->vibpos = 0;
292 	      track->effect |= EFF_VIBRATO;
293               break;
294       /* Choose and offset starting into the sample */
295       case 9: if (!param)
296                    param = track->oldsampofs;
297               track->oldsampofs = param;
298               track->position = ((uint16)param) << 8;
299               break;
300       case 5:    track->effect |= EFF_PORT_TO;
301       case 6:    if (effect == 6)
302   	           track->effect |= EFF_VIBRATO;
303       case 0x0A: track->vol_slide = ((param & 0xF0) >> 4) - (param & 0x0F);
304 #ifdef DEBUG
305 	         printf("vol slide %d param %02X\n",track->vol_slide,param);
306 #endif
307 	         track->effect |= EFF_VOL_SLIDE;
308 	         break;
309       /* Jump to a different position */
310       case 0x0B: if (!loop_mod) break;
311 	         order_pos = param;
312                  row = 64;
313                  break;
314       /* Set volume of this track */
315       case 0x0C: if (param > 64) track->volume = 64;
316                    else track->volume = param;
317                  break;
318       /* Jumps to specified pattern-position in next song position */
319       case 0x0D: break_row = ((param & 0xF0) >> 4) * 10 + (param & 0x0F);
320                  row = 64;
321                  break;
322       case 0x0E: i = param & 0xF0;
323                  param &= 0x0F;
324                  switch (i)
325                  {
326                    case 1: track->period += param;
327                            if (track->period > track->period_high_limit)
328 			      track->period = track->period_high_limit;
329                            track->pitch = track->finetune_rate / track->period;
330                            break;
331                    case 2: track->period -= param;
332                            if (track->period < track->period_low_limit)
333 			      track->period = track->period_low_limit;
334                            track->pitch = track->finetune_rate / track->period;
335                            break;
336                  }
337                  break;
338       /* Set song speed */
339       case 0x0F: if (param)
340                  {
341 #ifdef GUS
342 		   gus_set_speed(param);
343 #endif /* GUS */
344 
345                    if (param < 32)
346                    {
347                      tempo = param;
348                      tempo_wait = param;
349                      break;
350                    }
351                    bpm = param;
352                    bpm_samples = mixspeed / ((103 * param) >> 8);
353                                           /*  103 */
354                  }
355                  break;
356     }
357   }
358 }
359 
startplaying(int loud)360 void startplaying(int loud)
361 {
362   uint16 i;
363   track_info_ptr track;
364   uint32 pitch_const;
365   int16 j;
366   int8 *vol_adj = loud ? loud_vol_adj : normal_vol_adj;
367 
368   order_pos = 0;
369   tempo_wait = tempo = mod.tempo;
370   bpm = mod.bpm;
371   row = 64;
372   break_row = 0;
373   bpm_samples = mixspeed / ((24*bpm)/60);
374                         /*   24*DEF_BPM  */
375 
376   track = tracks;
377   for (i=0;i<MAX_TRACKS;i++)
378   {
379     track->samples = 0;
380     track->position = 0;
381     track->length = 0;
382     track->repeat = 0;
383     track->replen = 0;
384     track->volume = 0;
385     track->error = 0;
386     track->period = 0;
387     track->pitch = 0;
388     track->effect = 0;
389     track->portto = 0;
390     track->vibpos = 0;
391     track->oldsampofs = 0;
392     track->oldperiod = 1;
393     track->arp[0] = 0;
394     track->arp[1] = 0;
395     track->arp[2] = 0;
396     track->arpindex = 0;
397     track++;
398   }
399   buf_ptr = 0;
400   buf_len = 0;
401 
402   if (mod.s3m)
403   {
404     for (i=0;i<MAX_SAMPLES;i++)
405     {
406       mod.finetune_rate[i] =
407           (((428l * mod.finetune_value[i]) << 8) / mixspeed);
408       mod.period_low_limit[i] = 0xE;
409       mod.period_high_limit[i] = 0x6B0;
410 /*
411       printf("mod period low limit %d %u %u %u\n",i,mod.period_low_limit[i],
412 	      min_length,mod.finetune_rate[i]);
413 
414       uint32 min_period;
415       uint16 min_length;
416 
417       if (mod.sample_length[i])
418       {
419          min_length = mod.sample_length[i];
420          if (mod.repeat_length[i] > 2)
421             min_length = mod.repeat_length[i];
422          min_period = (mod.finetune_rate[i] / min_length)+1;
423          if (min_period < 40)
424             min_period = 40;
425          mod.period_low_limit[i] = min_period;
426       }
427 */
428     }
429   } else
430   {
431     for (i=0;i<MAX_SAMPLES;i++)
432     {
433       mod.finetune_rate[i] = (((((uint32)428ul) * ((uint32)MIDCRATE))
434 	                      << 8) / (uint32)mixspeed);
435       mod.period_low_limit[i] = 113;
436       mod.period_high_limit[i] = 856;
437     }
438   }
439 
440   if (bit16)
441   {
442     if (mod.tracks < 5)
443      for (j=0;j<16640;j++)
444            vol.vol_table16[j] = (vol_adj[(j >> 8)] * ((j-0x80) & 0xFF));
445      else
446      for (j=0;j<16640;j++)
447      {
448            vol.vol_table16[j] = (vol_adj[(j >> 8)] * ((j-0x80) & 0xFF)) >> 1;
449        }
450   } else
451   {
452     if (mod.tracks < 5)
453      for (j=0;j<16640;j++)
454          vol.vol_table[j] = (vol_adj[(j >> 8)] * (int)((char)j) ) >> 8;
455      else
456      for (j=0;j<16640;j++)
457          vol.vol_table[j] = (vol_adj[(j >> 8)] * (int)((char)j) ) >> 9;
458   }
459 }
460 
dump_mod(song_data * data)461 void dump_mod(song_data *data)
462 {
463   int16 i;
464 
465   for (i=0;i<128;i++)
466     if (data->patterns[i])
467     {
468       free(data->patterns[i]);
469       data->patterns[i] = NULL;
470     }
471   for (i=0;i<MAX_SAMPLES;i++)
472     if (data->samples[i])
473     {
474       free(data->samples[i]);
475       data->samples[i] = NULL;
476     }
477 }
478 
print_name_nice(char * string,int len)479 void print_name_nice(char *string, int len)
480 {
481   while ((len>0) && (*string))
482   {
483     if ((*string < ' ') || (*string > '~'))
484       putchar(' ');
485       else putchar(*string);
486     string++;
487     len--;
488   }
489   while (len>0)
490   {
491     putchar(' ');
492     len--;
493   }
494 }
495 
load_mod(char * filename,song_data * data,int8 noprint)496 int load_mod(char *filename, song_data *data, int8 noprint)
497 {
498   FILE *fp;
499   char **voice_31 = (char **) voice_31_list;
500   int i,voices;
501   int nopat = 0,len;
502   int pattern_len = 1024;
503   mod_voice mod_v;
504   song_15 song_v;
505 
506   char id[5];
507 
508   for (i=0;i<MAX_SAMPLES;i++)
509   {
510     data->samples[i] = NULL;
511     data->sample_length[i] = 0;
512   }
513   if (!(fp=fopen(filename,"rb")))
514   {
515 #ifdef DEBUG
516     printf("Could not open file '%s'\n",filename);
517 #endif
518     return (1);
519   }
520   fseek(fp, 1080, SEEK_SET);
521   if (fread((void *)id,sizeof(char),4,fp) != 4)
522   {
523 #ifdef DEBUG
524     printf("Could not read file id\n");
525 #endif
526     fclose(fp);
527     return (1);
528   }
529   fseek(fp, 0, SEEK_SET);
530   id[4] = 0;
531 #ifdef DEBUG
532   printf("Module ID = %s\n",id);
533 #endif
534 
535   while (*voice_31)
536    if (memcmp((void *)*voice_31,(void *)id,4)) voice_31++;
537     else break;
538 
539   if (fread(data->name,sizeof(char),20,fp) != 20)
540   {
541 #ifdef DEBUG
542     printf("Error loading name of mod!\n");
543 #endif
544     fclose(fp);
545     return (1);
546   }
547   data->name[19] = 0;
548   if (!noprint)
549   {
550     printf("Protracker Module name = \"");
551     print_name_nice(data->name,20);
552     printf("\"\n");
553   }
554   data->tracks = 4;
555   data->track_shift = 4;
556   if (*voice_31)
557   {
558     if (*voice_31 == voice_8chn)
559       data->tracks = 8;
560     if (*voice_31 == voice_6chn)
561       data->tracks = 6;
562     voices = 31;
563   } else voices = 15;
564   pattern_len = ((uint16)data->tracks) << 8;
565 
566 
567   /********************************************
568    *            load instruments              *
569    ********************************************/
570 
571 
572   for (i=0;i<voices;i++)
573   {
574 
575     if (fread(&mod_v,sizeof(mod_voice),1,fp) != 1)
576     {
577 #ifdef DEBUG
578       printf("Could not load voice #%d\n",i);
579 #endif
580       fclose(fp);
581       return (1);
582     }
583     data->sample_length[i] = big_endian(mod_v.sample_length) << 1;
584     data->finetune_value[i] = mod_v.finetune_value;
585     data->volume[i] = mod_v.volume;
586     data->repeat_point[i] = big_endian(mod_v.repeat_point) << 1;
587     data->repeat_length[i] = big_endian(mod_v.repeat_length) << 1;
588 /*
589     if (data->repeat_length[i] > data->sample_length[i])
590        data->repeat_length[i] = data->sample_length[i];
591  */
592     if (data->repeat_point[i] > data->sample_length[i])
593        data->repeat_point[i] = data->sample_length[i];
594     if ((data->repeat_point[i] + data->repeat_length[i]) >
595          data->sample_length[i])
596       data->repeat_length[i] = data->sample_length[i] - data->repeat_point[i];
597 
598     if (!noprint)
599     {
600       printf("%-2d %05u ",i,data->sample_length[i]);
601 #ifdef DEBUG
602       printf(" %05u %05u ",data->repeat_point[i],data->repeat_length[i]);
603 #endif
604       print_name_nice(mod_v.sample_name,22);
605       printf("  ");
606       if (i & 0x01) printf("\n");
607     }
608 
609 
610   }
611   if (!noprint)
612      printf("\n");
613   if (fread(&song_v,sizeof(song_15),1,fp) != 1)
614   {
615 #ifdef DEBUG
616     printf("Could not load song data\n");
617 #endif
618     fclose(fp);
619     return (1);
620   }
621   data->song_length_patterns = song_v.song_length_patterns;
622   data->song_repeat_patterns = song_v.song_repeat_patterns;
623   for (i=0;i<256;i++) data->positions[i] = song_v.positions[i];
624   if (voices != 15) fseek(fp,4,SEEK_CUR);
625 
626   if (data->song_repeat_patterns > data->song_length_patterns)
627     data->song_repeat_patterns = data->song_length_patterns;
628   for (i=0;i<128;i++)
629   {
630     if (nopat < data->positions[i])
631       nopat = data->positions[i];
632     data->patterns[i] = NULL;
633   }
634   for (i=0;i<=nopat;i++)
635   {
636 #ifdef DEBUG
637     printf("Loading pattern %d\n",i);
638 #endif
639     data->patterns[i] = (int8*) malloc(pattern_len);
640     if (data->patterns[i])
641     {
642       if (!fread((void *)data->patterns[i],pattern_len,1,fp))
643       {
644 #ifdef DEBUG
645         printf("Error reading pattern %d\n",i);
646 #endif
647         fclose(fp);
648         dump_mod(data);
649         return (1);
650       }
651     } else
652     {
653 #ifdef DEBUG
654       printf("Could not allocate memory for pattern %d\n",i);
655 #endif
656       fclose(fp);
657       dump_mod(data);
658       return (1);
659     }
660   }
661   for (i=0;i<voices;i++)
662   {
663     if (data->sample_length[i])
664     {
665 #ifdef DEBUG
666       printf("Loading sample %d length %u\n",i,data->sample_length[i]);
667 #endif
668       data->samples[i] = (int8 *) malloc(data->sample_length[i]);
669       if (data->samples[i])
670       {
671         if ((len=fread((void *)data->samples[i],sizeof(char),
672             data->sample_length[i],fp)) !=
673             data->sample_length[i])
674         {
675 #ifdef DEBUG
676           printf("Error reading sample %d %u\n",i,len);
677 #endif
678           fclose(fp);
679           dump_mod(data);
680           return (1);
681         }
682 
683 #ifdef GUS
684       if ((gus_dev != -1) && data->sample_length[i])
685 	{
686 	  struct patch_info *patch;
687 
688 	  patch = (struct patch_info *)
689 	    malloc( sizeof(*patch) + (uint16)data->sample_length[i]);
690 
691 	  patch->key = GUS_PATCH;
692 	  patch->device_no = gus_dev;
693 	  patch->instr_no = i;
694 
695 	  if (data->repeat_length[i] >= 4)
696 	    patch->mode = WAVE_LOOPING;
697           else
698             patch->mode = 0;
699 
700 	  patch->len  = data->sample_length[i];
701 	  patch->loop_start = data->repeat_point[i];
702 	  patch->loop_end = data->repeat_point[i] + data->repeat_length[i];
703 	  patch->base_note = 261630; /* middle C */
704 	  patch->base_freq = base_freq_table[data->finetune_value[i] & 0xf];
705 	  patch->low_note = 0;
706 	  patch->high_note = 20000000;
707 	  patch->volume = 120;
708 	  patch->panning = 16;
709 
710 	  /* ok, now copy the data into patch->data */
711 
712 	  memcpy(patch->data,data->samples[i],data->sample_length[i]);
713 
714 	  gus_patch_load(patch,i);
715 
716 	  /* there was some sample volume adjustment stuff here */
717 
718 	  free(patch);
719 	}
720 #endif /* GUS */
721 
722 
723       } else
724       {
725 #ifdef DEBUG
726         printf("Could not allocate memory for sample %d\n",i);
727 #endif
728         fclose(fp);
729         dump_mod(data);
730         return (1);
731       }
732     }
733   }
734 #ifdef DEBUG
735   printf("Length of file = %lu\n",ftell(fp));
736   fseek(fp,0,SEEK_END);
737   printf("Total length = %lu\n",ftell(fp));
738 #endif
739   fclose(fp);
740   data->tempo = options.def_tempo;
741   data->bpm = options.def_bpm;
742   data->s3m = 0;
743   return (0);
744 }
745 
746 
747 
748 
749